Message Bus

Message Bus

The Message Bus provides a loosely coupled way to exchange messages. A class sending a message invokes the Message Bus to send the message to a destination, while other classes (listeners) registered at that destination receive the message. The listeners are transparent to senders and vice-versa.

Here are the main messaging components:

Destinations: Logical (not physical), named locations where messages are sent.

Listeners: Classes that listen for messages sent to specific destinations.

Message Bus: The framework that handles destination registration and sends messages to listeners.

Messages: Objects that can contain a payload and metadata, including an optional response destination.

Senders: Arbitrary classes that invoke Message Bus to send messages to a destination’s listeners.

The figure below demonstrates component interaction.

Example Messaging Component Interaction

Here is an example interaction sequence:

  1. An arbitrary class sends a Message to a registered Destination.
  2. Message Bus dispatches the Message to the destionation’s registered MessageListeners.

The message sender is only concerned with using Message Bus to send the message to the destination; it is not concerned with the message recipients. The message listeners are only concerned with receiving messages at the destination; they are not concerned with the message sender.

Synchronous and Asynchronous Messaging

Message Bus sends messages synchronously and asynchronously.


Synchronous messaging was removed and is no longer supported for Liferay DXP 7.4 U49/Liferay Portal 7.4 GA49 and above.

Synchronous Messaging: The sender blocks after sending a message. When the sender’s condition (determined by the sender type) is met, the sender unblocks and continues processing.

Asynchronous Messaging: The sender immediately continues processing after sending a message.

The following topics cover both ways of messaging:

Tuning Performance

The Message Bus API facilitates monitoring registration events, destinations, destination message listeners, and message queues. You can configure Message Bus components to meet your needs by adjusting destination types, message queue parameters, and thread parameters. See Tuning Messaging Performance for more information.

What’s Next

Listening on Liferay’s built-in destinations is a great way to begin using Message Bus. Start with Listening for Messages next.