Search code examples
javascalaakkaactor

Akka subsequent tells


Are messages sent by subsequent tell invocations guaranteed to be processed by the actor in the order in which they were sent?

Example:

actor ! message1
actor ! message2

Will message1 and message2 be always seen by the actor in the order in which they were sent.


Solution

  • If message1 and message2 are sent in that order from the same thread, or from the same actor and they are sent to the same actor (and that actor is using a mailbox that does not reorder messages: the default mailbox does not, but one can implement mailboxes which reorder messages, e.g. in order to implement prioritization), message2 will not be received by the target actor before message1.

    Thus any of the of these four is possible:

    • message1 is received and then message2
    • message1 is received, but message2 is never received
    • message1 is never received, but message2 is
    • neither message1 nor message2 is ever received

    Note that there is no guarantee that two message sends to different actors will be received in any particular order. There is also no guarantee regarding the ordering of message sends from two different actors (or if outside of any actor (e.g. in a Future callback or the main method), a different thread)).