I discovered Akka relatively recently, and after reading the great “Akka in Action” book and various other materials, I’ve finally been dipping my toes into some coding. I’ve skipped starting to code with classic actors, in favour of typed actors.
When thinking about how to code some toy actors, one thing that has confused me somewhat is the the guidance around “Request-Response” and “Adapted Response”, described in Actor interaction patterns
In thinking about this myself, I think I have arrived at a correct understanding now, but would be happy for someone to give me some confirmation or denial
The following are the points in the documentation that initially surprised me (but it’s likely I’ve not correctly understood their meaning in this context):
My perspective is, if one actor is to send messages to another actor via that other actor’s protocol, why wouldn’t, and shouldn’t, this sending actor also support receiving the response portion of that other actor’s protocol? (If you ask me my name, you would and should be prepared for me to reply back to you with a response)
I see some examples of this “Request-Response” pattern in the documentation examples, such as the Gabbler using the ChatRoom’s protocol. (The Gabbler object imports ChatRoom._, and can thus send PostMessages to ChatRoom, and it receives response messages of ChatRoom’s protocol as well.)
However, I do see that it is perhaps odd (and constraining?), that the Gabbler’s Behavior is of type “SessionEvent”, which is of the ChatRoom actor protocol - not of its own.
Is it the Actor’s Behavior being typed of messages of another actor’s protocol which is the crux of the issue?
Because I can imagine that if the typed actor needs to accept both messages of its own protocol, in addition to communicating with other actors via their protocol, then that could be when the “Adapted Response” interaction pattern is useful to employ? (This would certainly seem to be a common situation for a system with a number of actors collaborating together.)
So, might I conclude that an Actor involved in different types of request-response protocols might typically, and justifiably, feature both:
- “Request-Response” style interaction (when viewed from its own perspective, as its “primary” protocol) - e.g. when it acts as the message recipient / responder
- “Adapted-Response” style for initiating communication with other Actors (when acting as the requester / response receiver)
?
PS - akka is fantastic!