Whilst working on a fairly large Akka application, I have come across a very simple structure when working with normal methods and non-Akka classes but which are actually quite
It seems to me like you don't necessarily need N stages to collect the responses. If you know how many responses you're waiting for you can collect them all under a single behavior.
Also, in any scenario where you are using ask
, you can easily replace it with an intermediary Actor to hold this context and pass all messages through tell
. That's actually what ask
does anyway, but the main differences are that you wouldn't have to deal with specifying timeouts for every ask
(well, you should still have a timeout for the overall request) and you can bundle all outstanding stages in a single Actor instead of an extra Actor for every ask
.
Jamie Allen has really good description of this scenario as the Extra and Cameo Patterns in Effective Akka.
So with all this in mind, you might be able to follow something along the lines of:
sender
Consumer in this Actor.tell
s. At this point you can make either the Cameo or the Connector as the Supervisor so your Supervision Strategies still work as you want.Receive
block can wait for responses from Connections. This doesn't have to be an await
on the ask
. Just accept the message in the receive
and then update your internal state.tell
.