Skip to content

[Messenger] Prioritized Transports example does not work #11967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jul 16, 2019 · 3 comments
Closed

[Messenger] Prioritized Transports example does not work #11967

ghost opened this issue Jul 16, 2019 · 3 comments
Labels
help wanted Issues and PRs which are looking for volunteers to complete them. Messenger

Comments

@ghost
Copy link

ghost commented Jul 16, 2019

For the Prioritized Transports, the example displayed does not work. I solved it in my code using two different dsn (not sure it is the best pratice).
In the doc, we have :

#.env
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages

#config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async_priority_high:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    # queue_name is specific to the doctrine transport
                    # try "exchange" for amqp or "group1" for redis
                    queue_name: high
            async_priority_low:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    queue_name: low

        routing:
            'App\Message\SmsNotification':  async_priority_low
            'App\Message\NewUserWelcomeEmail':  async_priority_high

It should be :

#.env
MESSENGER_TRANSPORT_DSN_HIGH=amqp://guest:guest@localhost:5672/%2f/messages_high
MESSENGER_TRANSPORT_DSN_LOW=amqp://guest:guest@localhost:5672/%2f/messages_low

#config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async_priority_high:
                dsn: '%env(MESSENGER_TRANSPORT_DSN_HIGH)%'
                options:
                    # queue_name is specific to the doctrine transport
                    # try "exchange" for amqp or "group1" for redis
                    queue_name: high
            async_priority_low:
                dsn: '%env(MESSENGER_TRANSPORT_DSN_LOW)%'
                options:
                    queue_name: low

        routing:
            'App\Message\SmsNotification':  async_priority_low
            'App\Message\NewUserWelcomeEmail':  async_priority_high
@weaverryan
Copy link
Member

weaverryan commented Jul 17, 2019

The problem is that the docs assume you're using the doctrine transport - and the queue_name is specific to the doctrine transport. If you look at the docs - https://symfony.com/doc/current/messenger.html#prioritized-transports - there is a comment that says:

# queue_name is specific to the doctrine transport
# try "exchange" for amqp or "group1" for redis

Does that help? I think just changing queue_name to exchange would work for amqp - can you confirm?

Side note - we need to add "option" validation to the transport. The amqp transport should (in a perfect world) throw an exception if this non-existent queue_name option is passed to it.

@ghost
Copy link
Author

ghost commented Jul 17, 2019

Hi @weaverryan, Thanks for your answer.

With amqp, according to the doc, we should have this :

#.env
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages

#config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async_priority_high:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    exchange:
                        name: 'high'
            async_priority_low:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    exchange:
                        name: 'low'

        routing:
            'App\Message\SmsNotification':  async_priority_low
            'App\Message\NewUserWelcomeEmail':  async_priority_high

But if I launch this command : sf messenger:consume async_priority_high -vvv
all messages from both transports will be handled.

In Symfony\Component\Messenger\Transport\AmqpExt\Connection, in the function fromDsn(...), we can see 2 options named 'exchange' and 'queues' :

$exchangeOptions = $amqpOptions['exchange'];
$queuesOptions = $amqpOptions['queues'];

Maybe I should set something for queue option but I don't know what :(

That's the reason why I created 2 variables, MESSENGER_TRANSPORT_DSN_HIGH and MESSENGER_TRANSPORT_DSN_LOW to bypass the problem.

@javiereguiluz javiereguiluz added the help wanted Issues and PRs which are looking for volunteers to complete them. label Sep 18, 2019
@javiereguiluz
Copy link
Member

I'm closing this one because the original user account has been deleted, so we can't get more feedback and Ryan mentioned that this is probably OK if you follow the entire docs. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues and PRs which are looking for volunteers to complete them. Messenger
Projects
None yet
Development

No branches or pull requests

2 participants