Description
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
).