Skip to content

Commit be2eb6f

Browse files
committed
[Messenger][AMQP] Use delivery_mode=2 by default
1 parent 96f04d9 commit be2eb6f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function testItSetupsTheConnectionWithDefaults()
227227
);
228228

229229
$amqpExchange->expects($this->once())->method('declareExchange');
230-
$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => []]);
230+
$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
231231
$amqpQueue->expects($this->once())->method('declareQueue');
232232
$amqpQueue->expects($this->once())->method('bind')->with(self::DEFAULT_EXCHANGE_NAME, null);
233233

@@ -250,7 +250,7 @@ public function testItSetupsTheConnection()
250250
$factory->method('createQueue')->will($this->onConsecutiveCalls($amqpQueue0, $amqpQueue1));
251251

252252
$amqpExchange->expects($this->once())->method('declareExchange');
253-
$amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', AMQP_NOPARAM, ['headers' => []]);
253+
$amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
254254
$amqpQueue0->expects($this->once())->method('declareQueue');
255255
$amqpQueue0->expects($this->exactly(2))->method('bind')->withConsecutive(
256256
[self::DEFAULT_EXCHANGE_NAME, 'binding_key0'],
@@ -373,7 +373,7 @@ public function testItDelaysTheMessage()
373373
$delayQueue->expects($this->once())->method('declareQueue');
374374
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__5000');
375375

376-
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo']]);
376+
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__5000', AMQP_NOPARAM, ['headers' => ['x-some-headers' => 'foo'], 'delivery_mode' => 2]);
377377

378378
$connection = Connection::fromDsn('amqp://localhost', [], $factory);
379379
$connection->publish('{}', ['x-some-headers' => 'foo'], 5000);
@@ -415,7 +415,7 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
415415
$delayQueue->expects($this->once())->method('declareQueue');
416416
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages__120000');
417417

418-
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000', AMQP_NOPARAM, ['headers' => []]);
418+
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages__120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
419419
$connection->publish('{}', [], 120000);
420420
}
421421

@@ -447,12 +447,27 @@ public function testAmqpStampHeadersAreUsed()
447447
$amqpExchange = $this->createMock(\AMQPExchange::class)
448448
);
449449

450-
$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y']]);
450+
$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y'], 'delivery_mode' => 2]);
451451

452452
$connection = Connection::fromDsn('amqp://localhost', [], $factory);
453453
$connection->publish('body', ['Foo' => 'X'], 0, new AmqpStamp(null, AMQP_NOPARAM, ['headers' => ['Bar' => 'Y']]));
454454
}
455455

456+
public function testAmqpStampDelireryModeIsUsed()
457+
{
458+
$factory = new TestAmqpFactory(
459+
$this->createMock(\AMQPConnection::class),
460+
$this->createMock(\AMQPChannel::class),
461+
$this->createMock(\AMQPQueue::class),
462+
$amqpExchange = $this->createMock(\AMQPExchange::class)
463+
);
464+
465+
$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 1]);
466+
467+
$connection = Connection::fromDsn('amqp://localhost', [], $factory);
468+
$connection->publish('body', [], 0, new AmqpStamp(null, AMQP_NOPARAM, ['delivery_mode' => 1]));
469+
}
470+
456471
public function testItCanPublishWithTheDefaultRoutingKey()
457472
{
458473
$factory = new TestAmqpFactory(
@@ -519,7 +534,7 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument
519534
$delayQueue->expects($this->once())->method('declareQueue');
520535
$delayQueue->expects($this->once())->method('bind')->with('delays', 'delay_messages_routing_key_120000');
521536

522-
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000', AMQP_NOPARAM, ['headers' => []]);
537+
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_messages_routing_key_120000', AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2]);
523538
$connection->publish('{}', [], 120000, new AmqpStamp('routing_key'));
524539
}
525540

src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string
231231
{
232232
$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];
233233
$attributes['headers'] = array_merge($attributes['headers'] ?? [], $headers);
234+
$attributes['delivery_mode'] = $attributes['delivery_mode'] ?? 2;
234235

235236
$exchange->publish(
236237
$body,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy