Skip to content

Latest commit

 

History

History
113 lines (92 loc) · 3.69 KB

2023-10-23-add-new-async-low-priority-queue.md

File metadata and controls

113 lines (92 loc) · 3.69 KB
title issue author author_email author_github
Add new low_priority queue
NEXT-31249
Frederik Schmitt
f.schmitt@shopware.com
fschmtt

Core

  • Added new messenger transport low_priority to src/Core/Framework/Resources/config/packages/framework.yaml
  • Added new parameter env(MESSENGER_TRANSPORT_LOW_PRIORITY_DSN) to src/Core/Framework/Resources/config/packages/framework.yaml which defaults to Doctrine
  • Added new subscriber Shopware\Core\Framework\MessageQueue\Subscriber\ConsumeMessagesSubscriber to automatically handle low_priority queue

Upgrade Information

Transport can be overridden on message level

If you explicitly configure a message to be transported via the async (default) queue, even though it implements the LowPriorityMessageInterface which would usually be transported via the low_priority queue, the transport is overridden for this specific message.

Example:

<?php declare(strict_types=1);

namespace Your\Custom;

class LowPriorityMessage implements LowPriorityMessageInterface
{
}
framework:
    messenger:
        routing:
            'Shopware\Core\Framework\MessageQueue\LowPriorityMessageInterface': low_priority
            'Your\Custom\LowPriorityMessage': async

Configure another transport for the "low priority" queue

The transport defaults to use Doctrine. You can use the MESSENGER_TRANSPORT_LOW_PRIORITY_DSN environment variable to change it.

Before:

parameters:
    messenger.default_transport_name: 'v65'
    env(MESSENGER_TRANSPORT_DSN): 'doctrine://default?auto_setup=false'

After:

parameters:
    messenger.default_transport_name: 'v65'
    env(MESSENGER_TRANSPORT_DSN): 'doctrine://default?auto_setup=false'
    env(MESSENGER_TRANSPORT_LOW_PRIORITY_DSN): 'doctrine://default?auto_setup=false&queue_name=low_priority'

For further details on transports with different priorities, please refer to the Symfony Docs: https://symfony.com/doc/current/messenger.html#prioritized-transports

Lower the priority for async messages

You might consider using the new low_priority queue if you are dispatching messages that do not need to be handled immediately. To configure specific messages to be transported via the low_priority queue, you need to either adjust the routing or implement the LowPriorityMessageInterface:

framework:
    messenger:
        routing:
            'Your\Custom\Message': low_priority

or

<?php declare(strict_types=1);

namespace Your\Custom;

class Message implements LowPriorityMessageInterface
{
}

Next Major Version Changes

Configure queue workers to consume low_priority queue

Explicitly configure your workers to additionally consume messages from the low_priority queue. Up to 6.6 the low_priority queue is automatically added to the workers, even if not specified explicitly.

Before:

php bin/console messenger:consume async

After:

php bin/console messenger:consume async low_priority

Configure another transport for the "low priority" queue

The transport defaults to use Doctrine. You can use the MESSENGER_TRANSPORT_LOW_PRIORITY_DSN environment variable to change it.

Before:

parameters:
    messenger.default_transport_name: 'v65'
    env(MESSENGER_TRANSPORT_DSN): 'doctrine://default?auto_setup=false'

After:

parameters:
    messenger.default_transport_name: 'v65'
    env(MESSENGER_TRANSPORT_DSN): 'doctrine://default?auto_setup=false'
    env(MESSENGER_TRANSPORT_LOW_PRIORITY_DSN): 'doctrine://default?auto_setup=false&queue_name=low_priority'

For further details on transports with different priorities, please refer to the Symfony Docs: https://symfony.com/doc/current/messenger.html#prioritized-transports