{"id":7002,"date":"2019-03-12T06:56:27","date_gmt":"2019-03-12T06:56:27","guid":{"rendered":"http:\/\/staging.modulebazaar.com\/blog\/?p=7002"},"modified":"2019-07-09T22:26:57","modified_gmt":"2019-07-10T02:26:57","slug":"rabbitmq-magento-2","status":"publish","type":"post","link":"https:\/\/www.modulebazaar.com\/blog\/rabbitmq-magento-2\/","title":{"rendered":"Instrumental Role of RabbitMQ in Magento 2"},"content":{"rendered":"<p>With the advent of RabbitMQ support in <strong><a href=\"https:\/\/www.modulebazaar.com\/modules\/magento2-extensions.html\" target=\"_blank\" rel=\"noopener noreferrer\">Magento 2<\/a><\/strong>, the asynchronous messaging capabilities of Magento have now become full-fledged. Let\u2019s have a quick look at asynchronous messaging before we get to know how RabbitMQ works.<\/p>\n<h2><b>Asynchronous Messaging<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Asynchronous Messaging is serial communication between two systems. The initiating system puts messages in a queue and proceeds to work on its other processes without waiting for an immediate response. Imagine a system where the sender and receiver need not be continually connected other than loose bindings based on rules of the message exchange. Just like how you would drop a mail in the postbox and the postman picks it up to eventually deliver to the addressee. One of the most popular asynchronous messaging protocols is the Advanced Message Queuing Protocol (AMQP).<\/span><\/p>\n<div id=\"attachment_7217\" style=\"width: 1034px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-7217\" loading=\"lazy\" class=\"size-large wp-image-7217\" src=\"https:\/\/www.egrovesys.com\/blog\/wp-content\/uploads\/2019\/03\/Set-1_v2-01-1024x282.jpg\" alt=\"RabbitMQ\" width=\"1024\" height=\"282\" \/><p id=\"caption-attachment-7217\" class=\"wp-caption-text\">RabbitMQ for asynchronous messaging<\/p><\/div>\n<p><span style=\"font-weight: 400;\">Recently, we had run into a task of making our Magento application transmit information to multiple applications and return quickly to its mainstream work. We turned to RabbitMQ \u2013 the lightweight yet feature-rich messaging solution which could also be deployed across distributed networks. It worked like a charm and was able to reduce the burden on our core Magento application and took care of sending the messages to appropriate third-party applications. Soon it was helping our application scale up and process 1,00,000 requests at ease from 25,000 earlier. What is this RabbitMQ then and how does it work<\/span><span style=\"font-weight: 400;\">?<\/span><\/p>\n<blockquote>\n<p><strong>Read also: <a href=\"https:\/\/www.modulebazaar.com\/blog\/5-of-the-best-magento-extensions-for-your-online-store\/\" target=\"_blank\" rel=\"noopener noreferrer\">5 Of The Best Magento Extensions For Your Online Store<\/a><\/strong><\/p>\n<\/blockquote>\n<h2><b>RabbitMQ<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">RabbitMQ is a message broker which primarily uses <strong><a href=\"https:\/\/news.decresearch.com\/unexpected-growth-seen-message-queue-software-market-2019-2025\/\" target=\"_blank\" rel=\"noopener noreferrer\">AMQP<\/a> <\/strong>for processing communications between 2 applications. It is a middleman where Queues can be defined and applications can connect to the Queues to pull the messages. Some tasks might be time-consuming. There would also be a need to handle multiple requests. The message broker puts these tasks into corresponding queues for the other application to process these independently.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Message Queuing allows web servers to respond quickly to requests and delegate them to a third party for processing rather than perform the task instantaneously. This helps in handling multiple, resource-intensive requests efficiently.<\/span><\/p>\n<h3><b>Components of RabbitMQ Architecture:<\/b><\/h3>\n<div id=\"attachment_7219\" style=\"width: 865px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-7219\" loading=\"lazy\" class=\" wp-image-7219\" src=\"https:\/\/www.egrovesys.com\/blog\/wp-content\/uploads\/2019\/03\/Set-2_v2-01-1024x436.jpg\" alt=\"RabbitMQ\" width=\"855\" height=\"364\" \/><p id=\"caption-attachment-7219\" class=\"wp-caption-text\">RabbitMQ components<\/p><\/div>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span style=\"font-weight: 400;\">Producer \u2013 The application or component which takes the requests from the users and pushes to the exchange. A request can either be a task, simple broadcast information or a file<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Exchange \u2013 The Exchange takes the request and sends to the queues \u00a0based on Exchange Type and rules for routing called \u2018Bindings\u2019<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Queue \u2013 These queues hold on to the request\/information until the appropriate Subscriber requests for the information. \u00a0The Queues are bound to exchanges identified by the \u2018Binding Key\u2019<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Consumer &#8211; These are dedicated systems that pull information from the queue and process them independently<\/span><\/li>\n<\/ul>\n<h3><b>Types of Exchange:<\/b><\/h3>\n<p><b>Topic Exchange &#8211;\u00a0<\/b><span style=\"font-weight: 400;\">Messages are routed based on a wildcard search result of the routing key with the binding key.<\/span><\/p>\n<p><b>Headers Exchange &#8211;\u00a0<\/b><span style=\"font-weight: 400;\">Messages are routed based on the Message Header with the Binding Header of the Queue.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Direct Exchange<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Messages are routed to the corresponding queue by exactly matching the binding key of the queue to the routing key of the message. This is the default exchange type of RabbitMQ.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Fanout Exchange<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Messages are routed to all the queues bound to the exchange.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><b>RabbitMQ in Magento 2<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Magento 2 added asynchronous messaging capabilities with the implementation of RabbitMQ.\u00a0<strong>Magento commerce<\/strong>\u00a0and Magento open source use RabbitMQ to manage message queues. As of Magento release 2.3.0, RabbitMQ can also be used on Magento open source installations.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Magento was using MySQL adapters for messaging and cron jobs to ensure delivery of messages. This wasn\u2019t reliable and scalable.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Typically, use RabbitMQ in situations where Magento needs to communicate with an ERP System or a dedicated logistics application. In a real-world scenario, using RabbitMQ would allow us to decouple an ERP integration process from the customer order fulfillment process. For example, when Magento triggers an Order Creation event, we would just pass the order id (message) into the order export message queue (publisher) and let the order complete normally. Now RabbitMQ queues the order ids (messages) until another process (consumer) takes an order id (message) and processes that order in its ERP System. Use RabbitMQ\u00a0to get back messages from the other systems into Magento 2. With the Consumer now running as a background process, we have great scalability, flexibility in runtime and better error handling.<\/span><\/p>\n<h2><strong>Possibilities for Implementing RabbitMQ in Magento 2 are huge:<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Queue up the desired number of scheduled tasks (cronjobs) in Magento and process asynchronously using RabbitMQ. With the growth of\u00a0<strong><a href=\"https:\/\/egrovesys.com\/ecommerce-marketplace-modules\/\" target=\"_blank\" rel=\"noopener noreferrer\">e-commerce<\/a><\/strong>\u00a0and increasing volume of orders, message queuing helps by decoupling resource intensive processes<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">\u00a0Furthermore, this improves the frontend response time giving a better user experience.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now let\u2019s see how to set up RabbitMQ and establish an asynchronous communication between a Publisher and a Consumer in Magento 2.<\/span><\/p>\n<p><b>Configure RabbitMQ<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Define the environment variables in the environment file located at \u2018app\/etc\/env.php\u2019<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">&#8216;queue&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt; [<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;amqp&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt; [<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;host&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;127.0.0.1&#8217;<\/span><\/i><i><span style=\"font-weight: 400;\">,<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;port&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;5672&#8217;<\/span><\/i><i><span style=\"font-weight: 400;\">,<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;user&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;guest&#8217;<\/span><\/i><i><span style=\"font-weight: 400;\">,<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;password&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;guest&#8217;<\/span><\/i><i><span style=\"font-weight: 400;\">,<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;virtualhost&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;\/&#8217;<\/span><\/i><i><span style=\"font-weight: 400;\">,<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;ssl&#8217;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=&gt; false<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0]<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">]<\/span><\/i><\/p>\n<h4><b>Setup the channel and type of the message to\u00a0communicate:<\/b><\/h4>\n<p><b>&#8220;communication.xml&#8221;<\/b><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">topic\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">name<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_topic_name&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">request<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;string&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">\/&gt;<\/span><\/i><\/p>\n<h4><b>Setup the exchange and bind the topic to the queue with a Binding Key:<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Interestingly, we have taken the TOPIC exchange type for example which is more flexible and adds scalability to the application.<\/span><\/p>\n<p><b>File: \u00a0\u00a0\u00a0\u00a0queue_topology.xml<\/b><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">exchange\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">name<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_exchange&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">type<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;topic&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">connection<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;amqp&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">autoDelete<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;true&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">durable<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;true&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;!&#8211; publisher &#8211;&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">binding\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">id<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;bindingid_publisher&#8221; \u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">topic<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_topic_name&#8221; \u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">destinationType<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;queue&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">destination<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;queue-name&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">\/<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;\/<\/span><\/i><i><span style=\"font-weight: 400;\">exchange<\/span><\/i><i><span style=\"font-weight: 400;\">&gt;<\/span><\/i><\/p>\n<h4><b>Set up the publisher and link to an exchange:<\/b><\/h4>\n<p><b>File: \u00a0\u00a0\u00a0queue_publisher.xml<\/b><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">publisher\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">topic<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_topic_name&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">connection\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">name<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;amqp&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">exchange<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_exchange&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">\/&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;\/<\/span><\/i><i><span style=\"font-weight: 400;\">publisher<\/span><\/i><i><span style=\"font-weight: 400;\">&gt;<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0As a matter of factly, we have now completed establishing the exchange and publisher, we will now setup the consumer side of communication channel.<\/span><\/p>\n<h4><b>Consumer Queue:<\/b><\/h4>\n<p><b>File: \u00a0\u00a0communication.xml<\/b><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">topic\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">name<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_topic_name&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">request<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;string&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">\/&gt;<\/span><\/i><\/p>\n<p><b>File: \u00a0queue_topology.xml<\/b><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">exchange\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">name<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_exchange&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">type<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;topic&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">connection<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;amqp&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">autoDelete<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;true&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">durable<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;true&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;!&#8211; consumer &#8211;&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">binding\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">id<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;bindingid_consumer&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">topic<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;sample_topic_name&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">destinationType<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;queue&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">destination<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;queue-name&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">\/&gt;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;\/<\/span><\/i><i><span style=\"font-weight: 400;\">exchange<\/span><\/i><i><span style=\"font-weight: 400;\">&gt;<\/span><\/i><\/p>\n<p><b>File: \u00a0\u00a0\u00a0queue_consumer.xml<\/b><\/p>\n<p><i><span style=\"font-weight: 400;\">&lt;<\/span><\/i><i><span style=\"font-weight: 400;\">consumer\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">name<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;consumer-name&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">queue<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;queue-name&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">connection<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;amqp&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">handler<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;className methodname&#8221;\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">consumerInstance<\/span><\/i><i><span style=\"font-weight: 400;\">=&#8221;Magento\\Framework\\MessageQueue\\BatchConsumer&#8221;<\/span><\/i><i><span style=\"font-weight: 400;\">\/&gt;<\/span><\/i><i><span style=\"font-weight: 400;\">::<\/span><\/i><\/p>\n<h4><b>Using the Publisher to push a message in Magento:<\/b><\/h4>\n<p><i><span style=\"font-weight: 400;\">use\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">Magento\\Framework\\MessageQueue\\PublisherInterface;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">public function\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">__construct(<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0PublisherInterface\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">$publisher<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">) {<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">$this<\/span><\/i><i><span style=\"font-weight: 400;\">-&gt;<\/span><\/i><i><span style=\"font-weight: 400;\">publisher\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">=\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">$publisher<\/span><\/i><i><span style=\"font-weight: 400;\">;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">}<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">public function\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">publishData()<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">{<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">$message = \u201ctest message\u201d;<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">$this<\/span><\/i><i><span style=\"font-weight: 400;\">-&gt;<\/span><\/i><i><span style=\"font-weight: 400;\">publisher<\/span><\/i><i><span style=\"font-weight: 400;\">-&gt;publish(<\/span><\/i><i><span style=\"font-weight: 400;\">&#8216;<\/span><\/i><i><span style=\"font-weight: 400;\">\u00a0sample_topic_name<\/span><\/i><i><span style=\"font-weight: 400;\">\u00a0&#8216;<\/span><\/i><i><span style=\"font-weight: 400;\">,\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">$message<\/span><\/i><i><span style=\"font-weight: 400;\">);<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">}<\/span><\/i><\/p>\n<h4><b>Run the Consumer from Terminal:<\/b><\/h4>\n<p><i><span style=\"font-weight: 400;\">bin\/magento queue:consumers:list<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">bin\/magento queue:consumers:start\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">[<\/span><\/i><i><span style=\"font-weight: 400;\">&#8211;max-messages<\/span><\/i><i><span style=\"font-weight: 400;\">=<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;value&gt;]\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">[<\/span><\/i><i><span style=\"font-weight: 400;\">&#8211;batch-size<\/span><\/i><i><span style=\"font-weight: 400;\">=<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;value&gt;]\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">[<\/span><\/i><i><span style=\"font-weight: 400;\">&#8211;pid-file-path<\/span><\/i><i><span style=\"font-weight: 400;\">=<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;value&gt;]\u00a0<\/span><\/i><i><span style=\"font-weight: 400;\">[<\/span><\/i><i><span style=\"font-weight: 400;\">&#8211;area-code<\/span><\/i><i><span style=\"font-weight: 400;\">=<\/span><\/i><i><span style=\"font-weight: 400;\">&lt;value&gt;] &lt;consumer_name&gt;<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Hope we were able to briefly explain about implementing RabbitMQ in Magento 2. The possibilities are now endless with the inclusion of RabbitMQ in Magento 2. Should you have any queries or feedback, please reach us on \u00a0<\/span><a href=\"https:\/\/mage@egrovesys.com\/\"><b><i>mage@egrovesys.com<\/i><\/b><\/a><\/p>\n<p><strong>Source: <a href=\"https:\/\/egrovesys.com\/blog\/rabbitmq-magento2\/\" target=\"_blank\" rel=\"noopener noreferrer\">RabbitMQ for Magento 2<\/a><\/strong><\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the advent of RabbitMQ support in Magento 2, the asynchronous messaging capabilities of Magento have now become full-fledged. Let\u2019s have a quick look at asynchronous messaging before we get to know how RabbitMQ works. Asynchronous Messaging Asynchronous Messaging is serial communication between two systems. The initiating system puts messages in a queue and proceeds to work on its other processes without waiting for an immediate response. Imagine a system where the sender and receiver need not be continually connected other than loose bindings based on rules of the message exchange. Just like how you would drop a mail in the postbox and the postman picks it up to eventually deliver to the addressee. One of the most popular asynchronous messaging protocols is the Advanced Message Queuing Protocol (AMQP). Recently, we had run into a task of making our Magento application transmit information to multiple applications and return quickly to its mainstream work. We turned to RabbitMQ \u2013 the lightweight yet feature-rich messaging solution which could also be deployed across distributed networks. It worked like a charm and was able to reduce the burden on our core Magento application and took care of sending the messages to appropriate third-party applications. [&hellip;]<\/p>\n","protected":false},"author":42,"featured_media":7453,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1177,1100,1147],"tags":[947,1201,1110,1148,1196],"yst_prominent_words":[1278,1288,1274,1280,1276,1283,1277,1286,1272,1282,1281,1287,1273,1285,1270,1279,1284,1271,1289,1275],"_links":{"self":[{"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/posts\/7002"}],"collection":[{"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/comments?post=7002"}],"version-history":[{"count":12,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/posts\/7002\/revisions"}],"predecessor-version":[{"id":7470,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/posts\/7002\/revisions\/7470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/media\/7453"}],"wp:attachment":[{"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/media?parent=7002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/categories?post=7002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/tags?post=7002"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.modulebazaar.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=7002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}