How can we set Shopware 6 to work with RabbitMQ?

Hello all. Does anyone knows how to set RabbitMQ to work togheter with Shopware 6 instead of default transport messaging? As starting point I had a look on vendor/shopware/core/Framework/Resources/config/packages/enqueue.yaml and vendor/shopware/core/Framework/Resources/config/packages/framework.yaml. I’m not sure how to specify sw6 to use rabbitMQ driver and how to set the queue name and other required parameters like host,port,…

We’ve tried to set in vendor/shopware/core/Framework/Resources/config/packages/enqueue.yaml:

enqueue:
    default:
        transport:
            dsn: "stomp+rabbitmq://guest:guest@localhost:5672"
            factory_service: Shopware\Core\Framework\MessageQueue\Enqueue\ConnectionFactoryFactory
        client: ~

But we have the following error:

“Attempted to load class “Client” from namespace “RabbitMq\ManagementApi”.↵Did you forget a “use” statement…”

vendor/enqueue/enqueue/Client/Driver/StompManagementClient.php on line 27. Seems the 

 RabbitMq\ManagementApi\Client doesn't exists

Any help will be appreciated. Thank you!

 

Hello,

I’ve managed to make it work and just want to share it with you. Steps are:

Inside your plugin main file MyPlugin.php:

buildConfig($container);
    }

    private function buildConfig(ContainerBuilder $container): void
    {
        $locator = new FileLocator('Resources/config');

        $resolver = new LoaderResolver([
            new XmlFileLoader($container, $locator),
            new YamlFileLoader($container, $locator),
            new IniFileLoader($container, $locator),
            new PhpFileLoader($container, $locator),
            new GlobFileLoader($container, $locator),
            new DirectoryLoader($container, $locator),
            new ClosureLoader($container),
        ]);

        $configLoader = new DelegatingLoader($resolver);

        $confDir = $this->getPath() . '/Resources/config';

        $configLoader->load($confDir . '/{packages}/*' . Kernel::CONFIG_EXTS, 'glob');

        $env = $container->getParameter('kernel.environment');
        $configLoader->load($confDir . '/{packages}/' . $env . '/*' . Kernel::CONFIG_EXTS, 'glob');
    }
}

This will load up not only from xml file but also from yaml…

Add yaml files into /src/Resources/config/packages directory

enqueue.yaml:

enqueue:
    rabbitmq:
        transport:
            dsn: "%env(string:default:default_whitespace:SHOPWARE_RABBITMQ_ENQUEUE_DSN)%"
        client: ~

framework.yaml:

 framework: messenger: transports: default: dsn: "%env(string:default:default\_whitespace:SHOPWARE\_RABBITMQ\_FRAMEWORK\_DSN)%"

.env:

 SHOPWARE\_RABBITMQ\_ENQUEUE\_DSN=amqp://guest:guest@rabbitmq-hostt:5672/%2F?connection\_timeout=1000&heartbeat=100 SHOPWARE\_RABBITMQ\_FRAMEWORK\_DSN=enqueue://rabbitmq?queue[name]=my-queue

where ‘my-queue’ is the queue   created in RabbitMQ Management interface.

Additionaly you could disable the admin worker by adding a shopware.yaml file into /src/Resources/config/packages:

shopware.yaml:

shopware:
  admin_worker:
    enable_admin_worker: false

But be sure to consume the queue messages by calling/setting a cron that will do bin/console messenger:consume

Regards,

Sorin

1 „Gefällt mir“