简体   繁体   中英

Is batch message sending possible with Sink.actorRefWithAck?

I'm using Akka Streams and I came across Sink.actorRefWithAck . I understand that it sends a message and only tries pulling in another element from the stream when an acknowledgement for the previous message has been received. Is there a way to batch-process messages with this sink? Example: pull five messages and only pull the next five once the first five have been acknowledged. I've thought about something like

source.grouped(5).to(Sink.actorRefWithAck(...))

But that would require the receiver to change to work with sequences, which let's assume is out of the question.

No, that is not possible with Sink.actorRefWithAck() while keeping individual messages being queued in the actor mailbox rather than the entire batch.

One idea to queue up messages in the actor inbox more eagerly would be to use source.mapAsync(n)(ask-actor).to(Sink.ignore) . This would send n to the actor and then as soon as the first one gets a response from the actor, it would pull and enqueue a new element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM