Message Queue pattern


In the Microservices architecture, we design the system by loosely coupled services and not anymore a single bloc. The services for inter-process need to communicate with each other:

  • Communication needs to be asynchronous to keep services loosely coupled.
  • Communication needs to be in real time and near real time.
  • For some cases, we need notification about the communication state.

Message Queue pattern definition

A message queue is a software engineering component used for communication between processes or between threads within the same process. Message queues provide an asynchronous communication protocol in which the sender and receiver of messages don't need to interact at the same time, so messages are held in queue until the recipient retrieves them in Publish/Subscribe way. The sender is the Producer of the message. The Producer Exchanges the message to the Messages Bus (Broker). The Broker exposes this message in a Queue for the Consumer for which he is subscribed.

Consumer acknowledgments

Systems that use a Messages Bus are by definition distributed. Since protocol methods (messages) sent are not guaranteed to reach the peer or be successfully processed by it, both publishers and consumers need a mechanism for delivery and processing confirmation. Several messaging protocols provide such features (AMQP1, STOMP2, MQTT3 ...). Delivery processing acknowledgments from consumers to Broker are known as acknowledgments; Broker acknowledgments to publishers are a protocol extension called publisher confirms.

Integration with other patterns

Using Message Queue pattern with Database per service pattern4 and CQRS pattern5, we will have:

  • Command services with their own isolated Command Stores, publishing events into the Messages Bus.
  • Query services subscribed to the Message Queue, consuming events to update their own Query Stores.

1. “AMQP - Advanced Message Queuing Protocol”, Wikipedia,
2. “STOMP - Simple Text Oriented Message Protocol”, Wikipedia,
3. “MQTT - Message Queuing Telemetry Transport”, Wikipedia,
4. “Database per service pattern”, This content
5. "CQRS - Command and Query Responsibility Segregation pattern", This content

results matching ""

    No results matching ""