Shopware resources and help articles

Simple and to the point. Optimized by the community.

Exchange Enqueue Database Queue Handler with RabbitMQ

0
by Thomas Holm Thomsen, last modified on April 25th, 2022

By default Shopware uses the database to handle messages added to and processed from queues. This is slow and puts unnecessary strain onto the database. Follow these steps to replace the database queue with the RabbitMQ system.

Dependencies

composer require enqueue/amqp-ext

Config Setup

Add custom enqueue handler. Create a config/packages/enqueue.yaml file:

enqueue:
    amqp:
        transport: '%env(AMQP_URL)%'
        client: ~

Register your transport. Add this to your config/packages/framework.yaml file:

framework:
    messenger:
        transports:
            default: enqueue://amqp

In your .env file add the following line: AMQP_URL="amqp://guest:guest@rabbitmq:5672/%2f?connect_timeout=30&heartbeat=0"

Remember to change the login credentials and host name.

Now you're ready to use RabbitMQ as your message queue handler.

Production Queue Create Bug

There is a bug where the initial queue is only created in debug mode, not production mode. Fix it with this:

nano +123 vendor/sroze/messenger-enqueue-transport/QueueInteropTransport.php
# Remove if part. Line 123 and line 125

# Clear OPCache as well
php bin/console cache:clear

# Now you need to force adding jobs to the queue.
# fx:
php bin/console dal:refresh:index --use-queue -vvv

Or use this patch:

Ensure that RabbitMQ queues are also created in PROD mode.

@package sroze/messenger-enqueue-transport

--- QueueInteropTransport.php
+++ QueueInteropTransport.php
@@ -120,9 +120,7 @@
         $destination = $this->getDestination($envelope);
         $topic = $context->createTopic($destination['topic']);

-        if ($this->debug) {
-            $this->contextManager->ensureExists($destination);
-        }
+        $this->contextManager->ensureExists($destination);

         $interopMessage = $this->encodeMessage($envelope);

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?