Skip to content

supravatm/magento2-rabbitmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

RabbitMQ in Magento 2

A Magento 2.4.x module for integrating RabbitMQ as a message queue provider.


Overview

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.

Features

  • Integrates RabbitMQ with Magento 2.4.x message queue system
  • Supports AMQP protocol
  • Facilitates asynchronous tasks and decoupled architecture
  • Easy to configure and extend

Architecture

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.

Installation

Prerequisites

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.

Steps

  1. Clone the repository:

    git clone https://github.com/supravatm/Magento2-RabbitMQ.git
  2. Copy the module into your Magento installation:

    Place the module directory in app/code/SMG/RabbitMQExample.

  3. Enable the module:

    php bin/magento module:enable SMG_RabbitMQExample
    php bin/magento setup:upgrade
    php bin/magento cache:flush
  4. Configure RabbitMQ in Magento:

    Edit your app/etc/env.php file accordingly:

    'queue' => [
        'amqp' => [
            'host' => 'rabbitmq-host',
            'port' => '5672',
            'user' => 'guest',
            'password' => 'guest',
            'virtualhost' => '/'
        ]
    ]
  5. Verify installation:

    php bin/magento setup:di:compile

Publish message

php bin/magento example:rabbit:publish

Output will be

Message published successfully

Executing consumers queue

Check if the queue is registered by running

php bin/magento queue:consumers:list
Output
example.consumer

Run consumer example.consumer

php bin/magento queue:consumers:start example.consumer

Note:

For a production environment, will configure a cron job for the consumer is always running.

License

MIT

About

Magento 2.4.x RabbitMQ Module

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages