Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

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:

  1. A sends to B.
  2. B says "I'm too full for letter L."
  3. A is told this, and stores L (possibly in hard drive). A continues working.
  4. Once A is idle, he looks back at any letters and finds letters like L that actors (such as B) were too full to consume.
  5. A attempts to resend L to B.
  6. Process keeps repeating.

From what I have read I need to switch to a blocked queue. My impression is if A sends a message to B, but Bs mailbox is full, B will say "I'm full" and cause a timeout. This then gets sent to a DeadLetterActorRef called D.

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 Bs 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...