Shopware resources and help articles

Simple and to the point. Optimized by the community.

Custom Queues in RabbitMQ

2
by Thomas Holm Thomsen, last modified on August 26th, 2021

When using RabbitMQ (see references for setup guide) for Shopware it can be a good idea to use multiple queues for dedicated purposes. A good use case would be a dedicated queue for your integrations which often need to update thousands of entities several times a day. If you use the default queue for this, standard Shopware jobs such as indexing, cache warming, feed generation, etc. can get "stuck" behind thousands of integration messages.

Define Your Custom Queues

Add this to your config/packages/messenger.yaml file:

framework:
  messenger:
    transports:
            [...]
            # Custom queue definition
            [...]

Example:

framework:
  messenger:
    transports:
      wexo_integration:
        dsn: '%env(AMQP_URL)%'
        options:
          exchange:
            name: wexo_integration
            type: topic
            default_publish_routing_key: wexo_integration
          queues:
            wexo_integration:
              binding_keys: [wexo_integration]

The above example with create a queue named wexo_integration as an additonal queue to the default messages queue. You can define as many custom queues as you wish (see full example below).

Route Messages to the Custom Queues

In order to use the newly created queues you must explicitly define which messages should use which queues. This is done in the same config/packages/messenger.yaml file with the routing setting:

framework:
  messenger:
    transports:
      [...]
    routing:
          # <your-message-class>: <your-queue-name>
      'Wexo\Integration\Core\Content\IntegrationProduct\IntegrationProductEntity': [wexo_integration]

Consuming From the Custom Queues When multiple queues exist the messenger consume command will ask you which one to consume from:

You can consume from a specific queue directly:

php bin/console messenger:consume <queue>
# Example:
php bin/console messenger:consume wexo_integration

Full Example with Multiple Custom Queues

framework:
  messenger:
    transports:
      wexo_integration:
        dsn: '%env(AMQP_URL)%'
        options:
          exchange:
            name: wexo_integration
            type: topic
            default_publish_routing_key: wexo_integration
          queues:
            wexo_integration:
              binding_keys: [wexo_integration]

      wexo_discount_labels:
        dsn: '%env(AMQP_URL)%'
        options:
          exchange:
            name: wexo_discount_labels
            type: topic
            default_publish_routing_key: wexo_discount_labels
          queues:
            wexo_discount_labels:
              binding_keys: [wexo_discount_labels]

    routing:
      'Wexo\BusinessCentralOverride\Core\Content\IntegrationOrderStatus\IntegrationOrderStatusEntity': [wexo_integration]
      'Wexo\Integration\Core\Content\IntegrationDiscount\IntegrationDiscountEntity': [wexo_integration]
      'Wexo\Integration\Core\Content\IntegrationOrder\IntegrationOrderEntity': [wexo_integration]
      'Wexo\Integration\Core\Content\IntegrationPrice\IntegrationPriceEntity': [wexo_integration]
      'Wexo\Integration\Core\Content\IntegrationProduct\IntegrationProductEntity': [wexo_integration]
      'Wexo\Integration\Core\Content\IntegrationProfile\IntegrationProfileEntity': [wexo_integration]
      'Wexo\Integration\Core\Content\IntegrationPromotion\IntegrationPromotionEntity': [wexo_integration]

      'Wexo\ProductLabels\Component\ProductLabelsProductEntity': [wexo_discounts_labels]

Discussion

0 comments

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