A Magento 2.4.x module for integrating RabbitMQ as a message queue provider.
This example module provides seamless integration between Magento 2.4.x and RabbitMQ, enabling asynchronous communication and scalable message processing using the AMQP protocol. RabbitMQ acts as the message broker, handling queues generated by Magento's messaging framework.
- Integrates RabbitMQ with Magento 2.4.x message queue system
- Supports AMQP protocol
- Facilitates asynchronous tasks and decoupled architecture
- Easy to configure and extend
The module is designed to work with Magento’s native message queue system (introduced in Magento 2.3+). It leverages the AMQP adapter to route messages to RabbitMQ.
Key Components:
communication.xml
– Defines aspects of the message queue system that all - - communication types have in common.queue_consumer.xml
– Defines the relationship between an existing queue and its consumer.queue_topology.xml
– Defines the message routing rules and declares queues and exchanges.queue_publisher.xml
– Defines the exchange where a topic is published.
We declare our topic as example.topic
for example.
This tutorial assumes RabbitMQ is installed and running on localhost
on the standard port (5672)
. In case you use a different host, port or credentials, connections settings would require adjusting.
-
Clone the repository:
git clone https://github.com/supravatm/Magento2-RabbitMQ.git
-
Copy the module into your Magento installation:
Place the module directory in
app/code/SMG/RabbitMQExample
. -
Enable the module:
php bin/magento module:enable SMG_RabbitMQExample php bin/magento setup:upgrade php bin/magento cache:flush
-
Configure RabbitMQ in Magento:
Edit your
app/etc/env.php
file accordingly:'queue' => [ 'amqp' => [ 'host' => 'rabbitmq-host', 'port' => '5672', 'user' => 'guest', 'password' => 'guest', 'virtualhost' => '/' ] ]
-
Verify installation:
php bin/magento setup:di:compile
php bin/magento example:rabbit:publish
Output will be
Message published successfully
Check if the queue is registered by running
php bin/magento queue:consumers:list
example.consumer
Run consumer example.consumer
php bin/magento queue:consumers:start example.consumer
For a production environment, will configure a cron job for the consumer is always running.