At this point we’ve covered a number of Message Routers in addition to some less complex, but essential, messaging patterns. With regard to my discussion of Request-Response, Ramesh Mandaleeka asked a few questions about Actor Model and message delivery. One of his questions was “How [do you] handle message sequencing?”
With Akka and other Actor systems, in general you do not need to worry about the sequence in which messages will be received by an Actor as a result of direct message sends from another Actor. As discussed in the Akka documentation, direct messages from one Actor to a second Actor are always received in the order in which the first Actor sent them. To repeat just a bit of the Akka documentation here, assume the following:
- Actor A1 sends messages M1, M2, M3 to A2
- Actor A3 sends messages M4, M5, M6 to A2
Based on these two scenarios, we arrive at these facts:
- If M1 is delivered it must be delivered before M2 and M3
- If M2 is delivered it must be delivered before M3
- If M4 is delivered it must be delivered before M5 and M6
- If M5 is delivered it must be delivered before M6
- A2 can see messages from A1 interleaved with messages from A3
- Since there is no guaranteed delivery, any of the messages may be dropped, i.e. not arrive at A2
The bottom line here is, don’t be concerned about a sequence of basic messages sent directly from one Actor to another being received out of order. It just won’t happen.
. . .
The full text is now available as part of my book Reactive Enterprise with Actor Model on Safari Books Online.