Allows to retrieve an interface for publishing messages to the target topic.
Basically, the whole processing looks as follows:
- Messaging clients create new {@link MessageBusConnection connections} within the target message bus and{@link MessageBusConnection#subscribe(Topic,Object) subscribe} to the target {@link Topic topics};
- Every time somebody wants to send a message for particular topic, he or she calls current method and receives object that conforms to the {@link Topic#getListenerClass() business interface} of the target topic. Every method call on thatobject is dispatched by the messaging infrastructure to the subscribers. {@link Topic#getBroadcastDirection() broadcasting} is performed if necessary as well;
It's also very important to understand message processing strategy in case of
nested dispatches. Consider the following situation:
-
Subscriber1
and subscriber2
are registered for the same topic within the same message bus; Message1
is sent to that topic within the same message bus; - Queued messages delivery starts;
- Queued messages delivery ends as there are no messages queued but not dispatched;
Message1
is queued for delivery to both subscribers; - Queued messages delivery starts;
Message1
is being delivered to the subscriber1
; Subscriber1
sends message2
to the same topic within the same bus; - Queued messages delivery starts;
- Important:
subscriber2
is being notified about all queued but not delivered messages, i.e. its callback is invoked for the message1; - Queued messages delivery ends because all subscribers have been notified on the
message1
; Message2
is queued for delivery to both subscribers; - Queued messages delivery starts;
Subscriber1
is notified on message2
Subscriber2
is notified on message2
Thread-safety. All subscribers are notified sequentially from the calling thread.
Memory management. Returned objects are very light-weight and stateless, so, they are cached by the message bus in
'per-topic'
manner. That means that caller of this method is not obliged to keep returned reference along with the reference to the message for further publishing. It's enough to keep reference to the message bus only and publish like {@code 'messageBus.syncPublisher(targetTopic).targetMethod()'}.
@param topic target topic
@param < L> {@link Topic#getListenerClass() business interface} of the target topic
@return publisher for target topic