Skip to content
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

Symfony Messenger: Cannot Specify DSN x-message-ttl Queue Argument (Integer Expected by RabbitMQ) #29044

Closed
thomaskonrad opened this issue Oct 31, 2018 · 4 comments

Comments

@thomaskonrad
Copy link

Symfony version(s) affected: 4.1

Description
I'm using the Symfony Messenger component with RabbitMQ and I would like to define a transport DSN with an x-message-ttl queue argument like this:

amqp://<user>:<password>@localhost:5672/%2f/messages?queue[arguments][x-message-ttl]=10000

Now the DSN gets parsed in the Connection::fromDsn function as follows:

if (false === $parsedUrl = parse_url($dsn)) {
    // ...

With parse_url, all URL parameters are represented as strings in the result. What happens when I dispatch a message and RabbitMQ tries to create the exchange and the queue, is the following:

Server channel error: 406, message: PRECONDITION_FAILED - invalid arg 'x-message-ttl' for queue 'messages' in vhost '/': {unacceptable_type,longstr}

RabbitMQ expects an integer, but receives a string (longstr) and is therefore not able to proceed. To confirm that it would work if it were an integer, I attached a debugger and dynamically changed the value to an integer, and it indeed worked.

How to reproduce
Create a new Symfony project, add the Symfony Messenger component via Composer, install a RabbitMQ server, write a simple command that publishes a simple message on a queue, and use amqp://<user>:<password>@localhost:5672/%2f/messages?queue[arguments][x-message-ttl]=10000 as a DSN (with your own credentials).

Possible Solution
The Connection::fromDsn function should try to parse arguments as an integer if they are known to be integer-only (such as x-message-ttl, x-max-length, x-max-length-bytes, and x-max-priority).

@thePanz
Copy link
Contributor

thePanz commented Dec 8, 2018

I am working on this during the #SymfonyConHackday2018

@iambrianreich
Copy link

I'm migrating an API project over to Symfony 4 and just ran into this myself. To confirm this is ONLY a problem if you specify arguments in the DSN's query string, correct? If I specify my arguments within the transport configuratioin using options/queue/arguments as follows, it seems to work:

framework:
    messenger:
        transports:
            # Uncomment the following line to enable a transport named "amqp"
            my_transport:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%/my-queue'
                options:
                    queue:
                        arguments:
                            x-max-priority: 255

@thePanz
Copy link
Contributor

thePanz commented Jan 21, 2019

I guess so @reichwebconsulting , as the parameter (in your config) is handled as an integer value.

nicolas-grekas added a commit that referenced this issue Jan 29, 2019
… values (thePanz)

This PR was submitted for the 4.1 branch but it was merged into the 4.2 branch instead (closes #29532).

Discussion
----------

[Messenger] fixed RabbitMQ arguments not passed as integer values

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29044
| License       | MIT

RabbitMQ expects some arguments to be passed as integer values.
Make sure to cast those after parsing the DSN

\cc @thomaskonrad

Commits
-------

f19c035 [Messenger] fixed RabbitMQ arguments not passed as integer values
@weaverryan
Copy link
Member

I believe this was fixed in #29532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants