Skip to content

Commit 8297806

Browse files
Thomas Beaujeannicolas-grekas
Thomas Beaujean
authored andcommitted
[Messenger] Add config option 'arguments' for delay queues
1 parent 6d0565b commit 8297806

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
@@ -142,6 +142,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
142142
* * delay:
143143
* * queue_name_pattern: Pattern to use to create the queues (Default: "delay_%exchange_name%_%routing_key%_%delay%")
144144
* * exchange_name: Name of the exchange to be used for the delayed/retried messages (Default: "delays")
145+
* * arguments: array of extra delay queue arguments (for example: ['x-queue-type' => 'classic', 'x-message-deduplication' => true,])
145146
* * auto_setup: Enable or not the auto-setup of queues and exchanges (Default: true)
146147
*
147148
* * Connection tuning options (see http://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.tune for details):
@@ -386,7 +387,7 @@ private function createDelayQueue(int $delay, ?string $routingKey, bool $isRetry
386387
$queue = $this->amqpFactory->createQueue($this->channel());
387388
$queue->setName($this->getRoutingKeyForDelay($delay, $routingKey, $isRetryAttempt));
388389
$queue->setFlags(\AMQP_DURABLE);
389-
$queue->setArguments([
390+
$queue->setArguments(array_merge([
390391
'x-message-ttl' => $delay,
391392
// delete the delay queue 10 seconds after the message expires
392393
// publishing another message redeclares the queue which renews the lease
@@ -397,7 +398,7 @@ private function createDelayQueue(int $delay, ?string $routingKey, bool $isRetry
397398
// after being released from to DLX, make sure the original routing key will be used
398399
// we must use an empty string instead of null for the argument to be picked up
399400
'x-dead-letter-routing-key' => $routingKey ?? '',
400-
]);
401+
], $this->connectionOptions['delay']['arguments'] ?? []));
401402

402403
return $queue;
403404
}

0 commit comments

Comments
 (0)