RabbitMQ in Magento 2
RabbitMQ is the most widely deployed open source message broker that implements Advanced Message Queuing Protocol (AMQP) 0.9.1 specification. It provides client libraries for major programming languages.
When comes to Magento Commerce the Message Queue Framework (MQF) is a system that allows a module to publish messages to queues. The MQF uses RabbitMQ as the messaging broker, which provides a scalable platform for sending and receiving messages. It also includes a mechanism for storing undelivered messages.
The following diagram illustrates how the Message Queue Framework works.
- A publisher is a component that sends messages to an exchange and it knows which exchange to publish to and the format of the messages it sends.
- An exchange receives messages from publisher and transferred/routes them to queues. RabbitMQ supports multiple types of exchanges, but in Magento it uses topic exchanges only.
A topic includes a routing key, which contains text strings separated by dots. The sample format for a topic name is string1.string2.string3… - While setting rules for forwarding messages, the Broker allows you to use wildcards. You can use an asterisk (*) to replace one string or a pound sign (#) to replace 0 or more strings.
For example, order.* would filter on order.create and order.delete, but not order.sent.email. However order.# would filter on order.create, order.delete and order.sent.email. - A queue is a buffer that stores messages route by exchange.
- A consumer an end-point to receives messages. It knows which queue to consume. It can map processors of the message to a specific queue.
RabbitMQ runs on many operating systems and cloud environments, and provides a wide range of developer tools for most popular languages.