简体   繁体   English

Sink.actorRefWithAck 可以批量发送消息吗?

[英]Is batch message sending possible with Sink.actorRefWithAck?

I'm using Akka Streams and I came across Sink.actorRefWithAck .我正在使用 Akka Streams 并且遇到了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.我知道它会发送一条消息,并且仅在收到对上一条消息的确认后才尝试从 stream 中拉入另一个元素。 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.示例:拉取 5 条消息,只有在前 5 条消息被确认后才拉取接下来的 5 条消息。 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.不,这对于Sink.actorRefWithAck()是不可能的,同时保持单个消息在参与者邮箱而不是整个批次中排队。

One idea to queue up messages in the actor inbox more eagerly would be to use source.mapAsync(n)(ask-actor).to(Sink.ignore) .更急切地将参与者收件箱中的消息排队的一种想法是使用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.这会将n发送给参与者,然后一旦第一个从参与者那里得到响应,它就会拉出一个新元素并将其加入队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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