Skip to content
Benjamin Diedrichsen edited this page Oct 7, 2015 · 2 revisions

Dispatch of messages

MBassador supports synchronous and asynchronous modes for message publication as well as handler invocation.

Message publication

Publishing a message via one of the bus' publication methods will either block until the message has been delivered to all listeners (synchronous) or return immediately (asynchronous).

An asynchronous message publication will be queued and processed by one of the workers which will then take care of invoking the handlers in the same way a synchronous publication would. The queue uses a FIFO model such that asynchronously published messages are processed in the order of publication.

NOTE: There is NO WAY to guarantee message ordering using asynchronous message publication in a multi-threaded environment. Because message publication is not an atomic operation it might be interrupted without having pushed its message to the queue. Even with a single dispatcher thread working > on the queue of published messages, an ordered sequence of messages when published concurrently using multiple threads will not necessarily arrive in its original order.

Handler invocation

Independently of the message publication a single handler can be invoked either synchronously or asynchronously. Synchronous handler invocation means that the handler invocation runs in the same thread as the message publication. Asynchronous invocation will invoke the handler in a different thread and the message publication processing immediately continues with the invocation of the next handler. Both synchronous and asynchronous are implemented as IHandlerInvocation

Filtering

Filtering of messages can be done on a per message publication base using implementations of IMessageFilter. This type of filter is called once at the beginning of a message publication and depending on its outcome the publication will either proceed to invoke the registered handlers or result in the publication of a FilteredMessage event.

Custom handler invocations can be used to implement filtering per message handler

Clone this wiki locally