Skip to content

Commit 15b5097

Browse files
feature #48603 [Messenger][Amqp] Add config option 'arguments' for delay queues (Thomas Beaujean)
This PR was merged into the 7.1 branch. Discussion ---------- [Messenger][Amqp] Add config option 'arguments' for delay queues | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #44186 #46254 | License | MIT | Doc PR | symfony/symfony-docs#17553 Hi, this PR to allow to add extra arguments to the amqp delay queues that are automatically created. The use case: - I do not know in advance the name of the queues (handled by env variables) - The queues are created automatically by symfony if needed - I need the deduplication plugin in both the queue and the associated delays queues (enabled with the x-message-deduplication argument) - I do not want to rewrite all delay arguments, I just want to be able to add or rewrite some The associated configuration in messenger.yaml ``` transports: async: dsn: '%env(MESSENGER_DSN)%' options: queues: '%env(MESSENGER_ASYNC_QUEUE_NAME)%': arguments: x-queue-type: 'classic' x-message-deduplication: true delay: arguments: x-queue-type: 'classic' x-message-deduplication: true ``` Commits ------- 94ee8a22b5 [Messenger] Add config option 'arguments' for delay queues
2 parents dbfae5d + 8297806 commit 15b5097

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add option `delay[arguments]` in the transport definition
8+
49
6.0
510
---
611

Tests/Transport/ConnectionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ public function testSetsParametersOnTheQueueAndExchange()
185185
],
186186
],
187187
],
188+
'delay' => [
189+
'arguments' => [
190+
'x-queue-type' => 'classic',
191+
'x-message-deduplication' => true,
192+
],
193+
],
188194
'exchange' => [
189195
'arguments' => [
190196
'alternate-exchange' => 'alternate',

Transport/Connection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function __construct(#[\SensitiveParameter] array $connectionOptions, arr
143143
* * delay:
144144
* * queue_name_pattern: Pattern to use to create the queues (Default: "delay_%exchange_name%_%routing_key%_%delay%")
145145
* * exchange_name: Name of the exchange to be used for the delayed/retried messages (Default: "delays")
146+
* * arguments: array of extra delay queue arguments (for example: ['x-queue-type' => 'classic', 'x-message-deduplication' => true,])
146147
* * auto_setup: Enable or not the auto-setup of queues and exchanges (Default: true)
147148
*
148149
* * Connection tuning options (see http://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.tune for details):
@@ -387,7 +388,7 @@ private function createDelayQueue(int $delay, ?string $routingKey, bool $isRetry
387388
$queue = $this->amqpFactory->createQueue($this->channel());
388389
$queue->setName($this->getRoutingKeyForDelay($delay, $routingKey, $isRetryAttempt));
389390
$queue->setFlags(\AMQP_DURABLE);
390-
$queue->setArguments([
391+
$queue->setArguments(array_merge([
391392
'x-message-ttl' => $delay,
392393
// delete the delay queue 10 seconds after the message expires
393394
// publishing another message redeclares the queue which renews the lease
@@ -398,7 +399,7 @@ private function createDelayQueue(int $delay, ?string $routingKey, bool $isRetry
398399
// after being released from to DLX, make sure the original routing key will be used
399400
// we must use an empty string instead of null for the argument to be picked up
400401
'x-dead-letter-routing-key' => $routingKey ?? '',
401-
]);
402+
], $this->connectionOptions['delay']['arguments'] ?? []));
402403

403404
return $queue;
404405
}

0 commit comments

Comments
 (0)