Description
Symfony version(s) affected
6.4.0
Description
Imagine scenario: RabbitMQ with several exchanges, each exchange have multiple queues and there is routing defined for them. Queues have different usage, so for example you would like to run dedicated worker for queues with high traffic (with auto-scaling) and other worker that would consume cherry-picked queues from several transports, but only those with low traffic.
When you run consumer with cherry-picked queues you get warnings about non-existing queues (it's a PHP-level warning about non-existing array key). These warnings, even though technically valid, don't bring much value as it's intentional that some of the transports don't have some queues.
How to reproduce
With configuration like this:
framework:
messenger:
transports:
poc1:
dsn: 'amqp://...'
options:
exchange:
name: poc-exchange1
queues:
poc-queue1: ~
poc2:
dsn: 'amqp://...'
options:
exchange:
name: poc-exchange2
queues:
poc-queue2: ~
poc-queue3: ~
poc3:
dsn: 'amqp://...'
options:
exchange:
name: poc-exchange3
queues:
poc-queue4: ~
poc-queue5: ~
and usage like bin/console messenger:consume poc1 poc2 --queues=poc-queue1 --queues=poc-queue3
.
Possible Solution
$queueConfig = $this->queuesOptions[$queueName] ?? [];
should do the trick, especially that every further usage of $queueConfig
is behind null coallesce operator or isset()
.
Additional Context
ℹ️ I've added var_dump(array_keys($this->queuesOptions));
to Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection::queue()
to show what's happening there:
bin/console messenger:consume poc1 poc2 --queues=poc-queue1 --queues=poc-queue3
[OK] Consuming messages from transports "poc1, poc2".
// The worker will automatically exit once it has received a stop signal via the messenger:stop-workers command.
// Quit the worker with CONTROL-C.
// Re-run the command with a -vv option to see logs about consumed messages.
array(1) {
[0]=>
string(12) "poc-queue1"
}
PHP Warning: Undefined array key "poc-queue3" in /app/vendor/symfony/amqp-messenger/Transport/Connection.php on line 512
array(1) {
[0]=>
string(12) "poc-queue1"
}
PHP Warning: Undefined array key "poc-queue1" in /app/vendor/symfony/amqp-messenger/Transport/Connection.php on line 512
array(2) {
[0]=>
string(12) "poc-queue2"
[1]=>
string(12) "poc-queue3"
}
array(2) {
[0]=>
string(12) "poc-queue2"
[1]=>
string(12) "poc-queue3"
}