Does Akka's event bus guarantee message order?

I would like to keep the order the events entered the bus. For example if event1 then event2 where entered to the bus then a subscribed actor would get them in that order.

The question is if such order is guarantee, both on clustered and on single node actor system.


If you are using the event stream on the actor system ( system.eventStream ) and if you can guarantee a single thread is publishing, then yes, the order will be preserved. The subchannel classification flavor of the event bus (the kind tied to system.eventStream ) is really simple. There is a Map of basically class type to a list of subscribing actors. When an event is published, it gets the matching list of subscribers from the Map (if any) and then sends the message to each of them. So if only one thread was calling publish , then it would need to finish publishing event1 (and thus delivering it to the mailboxes of all subscribers) before moving on to event2. Actors process their mailboxes in the order that the messages were received (unless you are using a custom PriorityMailbox impl), so first in first out.

Now of course if you had multiple threads, I can't guarantee this in order processing as thread1 may start the publish first, but thread 2 might finish it first leading to what you would consider out of order.

链接地址: http://www.djcxy.com/p/23066.html

上一篇: Sails.js同一模型多对多协会

下一篇: Akka的活动巴士是否可以保证消息顺序?