Skip to content

Commit d3124bf

Browse files
committed
Keep setting "queue_name_pattern" backward compatible
1 parent f6e8c45 commit d3124bf

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ public function testItDelaysTheMessage()
416416
$delayExchange = $this->createMock(\AMQPExchange::class);
417417
$delayExchange->expects($this->once())
418418
->method('publish')
419-
->with('{}', 'delay_messages__delay_5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo'], 'delivery_mode' => 2]);
420-
$connection = $this->createDelayOrRetryConnection($delayExchange, self::DEFAULT_EXCHANGE_NAME, 'delay_messages__delay_5000');
419+
->with('{}', 'delay_messages__5000_delay', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo'], 'delivery_mode' => 2]);
420+
$connection = $this->createDelayOrRetryConnection($delayExchange, self::DEFAULT_EXCHANGE_NAME, 'delay_messages__5000_delay');
421421

422422
$connection->publish('{}', ['x-some-headers' => 'foo'], 5000);
423423
}
@@ -427,8 +427,8 @@ public function testItRetriesTheMessage()
427427
$delayExchange = $this->createMock(\AMQPExchange::class);
428428
$delayExchange->expects($this->once())
429429
->method('publish')
430-
->with('{}', 'delay_messages__retry_5000', AMQP_NOPARAM);
431-
$connection = $this->createDelayOrRetryConnection($delayExchange, '', 'delay_messages__retry_5000');
430+
->with('{}', 'delay_messages__5000_retry', AMQP_NOPARAM);
431+
$connection = $this->createDelayOrRetryConnection($delayExchange, '', 'delay_messages__5000_retry');
432432

433433
$amqpEnvelope = $this->createMock(\AMQPEnvelope::class);
434434
$amqpStamp = AmqpStamp::createFromAmqpEnvelope($amqpEnvelope, null, '');
@@ -460,7 +460,7 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
460460

461461
$connection = Connection::fromDsn('amqp://localhost', $connectionOptions, $factory);
462462

463-
$delayQueue->expects($this->once())->method('setName')->with('delay_messages__delay_120000');
463+
$delayQueue->expects($this->once())->method('setName')->with('delay_messages__120000_delay');
464464
$delayQueue->expects($this->once())->method('setArguments')->with([
465465
'x-message-ttl' => 120000,
466466
'x-expires' => 120000 + 10000,
@@ -469,9 +469,9 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
469469
]);
470470

471471
$delayQueue->expects($this->once())->method('declareQueue');
472-
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__delay_120000');
472+
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__120000_delay');
473473

474-
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__delay_120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
474+
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000_delay', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
475475
$connection->publish('{}', [], 120000);
476476
}
477477

@@ -579,7 +579,7 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument
579579

580580
$connection = Connection::fromDsn('amqp://localhost', $connectionOptions, $factory);
581581

582-
$delayQueue->expects($this->once())->method('setName')->with('delay_messages_routing_key_delay_120000');
582+
$delayQueue->expects($this->once())->method('setName')->with('delay_messages_routing_key_120000_delay');
583583
$delayQueue->expects($this->once())->method('setArguments')->with([
584584
'x-message-ttl' => 120000,
585585
'x-expires' => 120000 + 10000,
@@ -588,9 +588,9 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument
588588
]);
589589

590590
$delayQueue->expects($this->once())->method('declareQueue');
591-
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages_routing_key_delay_120000');
591+
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages_routing_key_120000_delay');
592592

593-
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_delay_120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
593+
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000_delay', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
594594
$connection->publish('{}', [], 120000, new AmqpStamp('routing_key'));
595595
}
596596

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
107107
$this->connectionOptions = array_replace_recursive([
108108
'delay' => [
109109
'exchange_name' => 'delays',
110-
'queue_name_pattern' => 'delay_%exchange_name%_%routing_key%_%action%_%delay%',
110+
'queue_name_pattern' => 'delay_%exchange_name%_%routing_key%_%delay%',
111111
],
112112
], $connectionOptions);
113113
$this->exchangeOptions = $exchangeOptions;
@@ -140,7 +140,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
140140
* * flags: Exchange flags (Default: AMQP_DURABLE)
141141
* * arguments: Extra arguments
142142
* * delay:
143-
* * queue_name_pattern: Pattern to use to create the queues (Default: "delay_%exchange_name%_%routing_key%_%action%_%delay%")
143+
* * 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")
145145
* * auto_setup: Enable or not the auto-setup of queues and exchanges (Default: true)
146146
* * prefetch_count: set channel prefetch count
@@ -382,13 +382,13 @@ private function createDelayQueue(int $delay, ?string $routingKey, bool $isRetry
382382

383383
private function getRoutingKeyForDelay(int $delay, ?string $finalRoutingKey, bool $isRetryAttempt): string
384384
{
385-
$action = $isRetryAttempt ? 'retry' : 'delay';
385+
$action = $isRetryAttempt ? '_retry' : '_delay';
386386

387387
return str_replace(
388-
['%delay%', '%exchange_name%', '%routing_key%', '%action%'],
389-
[$delay, $this->exchangeOptions['name'], $finalRoutingKey ?? '', $action],
388+
['%delay%', '%exchange_name%', '%routing_key%'],
389+
[$delay, $this->exchangeOptions['name'], $finalRoutingKey ?? ''],
390390
$this->connectionOptions['delay']['queue_name_pattern']
391-
);
391+
).$action;
392392
}
393393

394394
/**

0 commit comments

Comments
 (0)