Does Java – akka’s event bus guarantee message order?
I want to keep the sequence of events entering the bus
The problem is that if this order is guaranteed, whether on cluster nodes or single node actor systems
Solution
If you use event streams on the actor system (system. Eventstream), and if you can guarantee that a single thread is publishing, then yes, the order will be preserved The subchannel classification style of the event bus (the type bound to system. Eventstream) is very simple There is a basic class type map to the list of subscribers When publishing an event, it gets a list of matching subscribers from the map (if any) and sends a message to each subscriber Therefore, if only one thread is calling publish, it needs to finish publishing event1 (thus passing it to the mailboxes of all subscribers), and then go to event2 Actors processes mailboxes in the order they are received (unless you use a custom PriorityMail@R_73_2419 @Impl), so first in, first out
Of course, if you have multiple threads, I can't guarantee this order, because thread1 may start publishing first, but thread 2 may complete it first, so you don't think in order