重新发送Akka中的一封死信 [英] Resending a dead letter in Akka
问题描述
我有一堆演员互相发送大量消息。这些参与者的默认队列很可能会导致许多参与者的内存不足。
I have a bunch of actors that are sending a lot of messages to each other. It is very likely that the default queue for these actors would cause a lot of actors to run out of memory.
理想情况下,这就是我想发生的事情:
Ideally this is what I want to happen:
-
A
发送到B
。 -
B
说:我对字母L
太满了。 -
A
被告知,并存储L
(可能存储在硬盘中) )。A
继续工作。 -
A
空闲后,他回头看任何字母并发现像L
之类的字母(例如B
)演员都太满而无法使用。 -
A
尝试将L
重新发送到B
。 - 过程不断重复。
A
sends toB
.B
says "I'm too full for letterL
."A
is told this, and storesL
(possibly in hard drive).A
continues working.- Once
A
is idle, he looks back at any letters and finds letters likeL
that actors (such asB
) were too full to consume. A
attempts to resendL
toB
.- Process keeps repeating.
从我已阅读,我需要切换到阻止的队列。我的印象是,如果 A
向 B
发送消息,但 B
邮箱已满, B
会说我已满并导致超时。然后将其发送到名为 D
的 DeadLetterActorRef
。
From what I have read I need to switch to a blocked queue. My impression is if A
sends a message to B
, but B
s mailbox is full, B
will say "I'm full" and cause a timeout. This then gets sent to a DeadLetterActorRef
called D
.
问题在于使Akka的死信范式适应上述步骤。在第3步中,我需要一种方法来告诉 A
失败,并且应该保存该信件以备后用。似乎您通过让他们 subscribe
到 DeadLetter
事件总线来告诉这些演员。这迫使我让每个演员都订阅了 DeadLetter
事件总线。如果 A
发送失败,而 B
发送失败,则两个 A
和 B
s消息将发送到 DeadLetter
队列,并且两者都必须对彼此的消息进行排序死信找到他们需要的。这似乎效率低下。有没有更好的方法可以解决这个问题?
The problem is adapting Akka's "dead letter paradigm" to the steps described above. At step 3, I need a way of telling A
it failed and the letter should be saved for later. It seems that you "tell" these actors by having them subscribe
to the DeadLetter
event bus. That forces me to have every actor subscribed to the DeadLetter
event bus. If A
failed to send a message and B
failed to send a message both A
and B
s message would be sent to the DeadLetter
queue and both have to sort through each other's dead letters to find the one they need. This seems inefficient. Is there a better way to go about this?
注意:我不是想平衡死信,有些文章建议这样做
Note: I do not want to load balance the dead letters, which some articles suggest doing with the dead letter queue.
推荐答案
您正在寻找的行为称为反压力。
在使用akka流支持的akka中,请参见此演示文稿
https://www.lightbend.com/blog/understanding-akka-streams-back-pressure-and-asynchronous-architectures
The behavior you are looking for is called "back pressure". In akka that is supported using akka streams see this presentation https://www.lightbend.com/blog/understanding-akka-streams-back-pressure-and-asynchronous-architectures
这篇关于重新发送Akka中的一封死信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!