0

I have a symfony project wrapped in docker and a Redis queue configured.

Configurations:

messenger.yaml

parameters:
    env(CONSUMER_ID): '0'

framework:
    messenger:
        # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
        failure_transport: failed

        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
             async_priority_high:
                 dsn: 'redis://%env(REDIS_QUEUE_NAME)%:6379/messages/symfony/consumer-%env(CONSUMER_ID)%&auth=%env(REDIS_PASSWORD)%'
                 options:
                     redeliver_timeout: 10000
                     group: high
                 retry_strategy:
                     max_retries: 3
                         # milliseconds delay
                         delay: 2000
                         # causes the delay to be higher before each retry
                         # e.g. 1 second delay, 2 seconds, 4 seconds
                         multiplier: 2
                         max_delay: 0
             async_priority_low:
                 dsn: 'redis://%env(REDIS_QUEUE_NAME)%:6379/messages/symfony/consumer-%env(CONSUMER_ID)%&auth=%env(REDIS_PASSWORD)%'
                 options:
                     redeliver_timeout: 10000
                     group: low
                 # default configuration
                 retry_strategy:
                     max_retries: 3
                         # milliseconds delay
                         delay: 2000
                         # causes the delay to be higher before each retry
                         # e.g. 1 second delay, 2 seconds, 4 seconds
                         multiplier: 2
                         max_delay: 0
             failed: 'doctrine://default?queue_name=failed'

        routing:
            'App\Message\MessageHighPriority': async_priority_high
            'App\Message\MessageLowPriority': async_priority_low

Handlers:

<?php

namespace App\MessageHandler;

use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

final class Handler implements MessageHandlerInterface
{
    public function __construct(...)
    {
        ...
    }

    public function __invoke(MessageHighPriority $message)
    {
        ...
    }
}

But when I run the command

bin/console messenger:consume async_priority_high -vv

I see that MessagePriorityLow is processed regardless of which receiver I run and in what priority, that is, if I have both messages in the queue then when I run the command

bin/console messenger:consume async_priority_high async_priority_high -vv

first processed those messages that entered the queue first

In addition, if I explicitly specify in the Hanlker from_transport => async_priority_low for low priority, and run the command

bin/console messenger:consume async_priority_high async_priority_high -vv

I get the error that there is no handler for async_priority_low

What am I doing wrong?

AymDev
  • 6,626
  • 4
  • 29
  • 52
  • I don't know that much about the Redis transport but what is the difference between your high & low transports ? I can only see the `group` option but I think you're sending high & low messages to the same queue, can you confirm ? – AymDev Aug 27 '21 at 15:19
  • Yes, most likely it is, but the group is listed in the documentation for Redis https://symfony.com/doc/4.4/messenger.html#prioritized-transports – Artem Sityaev Aug 27 '21 at 15:27
  • Yes, `group` is listed as many other options, that's not the point. Correct me if I'm wrong but I think that **streams** are the *queues* in Redis and that you are in fact sending all your messages in the same place. – AymDev Aug 27 '21 at 15:35
  • @AymDev Yes, you're absolutely right, after setting up the `stream` everything started working as expected. Thank you! – Artem Sityaev Aug 27 '21 at 15:47
  • What was the final messenger.yaml configuration that made things with work with high and low priority queues? I've tried various configurations, but I'm still getting "could not acknowledge redis message" errors. – lfjeff Nov 13 '22 at 18:30

0 Answers0