Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3596948

Browse files
committed
feature #32489 [Messenger] Allow exchange type headers binding (CedrickOka)
This PR was merged into the 4.4 branch. Discussion ---------- [Messenger] Allow exchange type headers binding | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29983 | License | MIT | Doc PR | ø Taken over #29983, as a feature for 4.4. [Apparently useful](https://www.cloudamqp.com/blog/2015-09-03-part4-rabbitmq-for-beginners-exchanges-routing-keys-bindings.html). Commits ------- 3211caa Allow exchange type headers binding
2 parents ff63bb3 + 3211caa commit 3596948

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,33 @@ public function testItSetupsTheConnection()
273273
$connection->publish('body');
274274
}
275275

276+
public function testBindingArguments()
277+
{
278+
$amqpConnection = $this->createMock(\AMQPConnection::class);
279+
$amqpChannel = $this->createMock(\AMQPChannel::class);
280+
$amqpExchange = $this->createMock(\AMQPExchange::class);
281+
$amqpQueue = $this->createMock(\AMQPQueue::class);
282+
283+
$factory = $this->createMock(AmqpFactory::class);
284+
$factory->method('createConnection')->willReturn($amqpConnection);
285+
$factory->method('createChannel')->willReturn($amqpChannel);
286+
$factory->method('createExchange')->willReturn($amqpExchange);
287+
$factory->method('createQueue')->willReturn($amqpQueue);
288+
289+
$amqpExchange->expects($this->once())->method('declareExchange');
290+
$amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => []]);
291+
$amqpQueue->expects($this->once())->method('declareQueue');
292+
$amqpQueue->expects($this->exactly(1))->method('bind')->withConsecutive(
293+
[self::DEFAULT_EXCHANGE_NAME, null, ['x-match' => 'all']]
294+
);
295+
296+
$dsn = 'amqp://localhost?exchange[type]=headers'.
297+
'&queues[queue0][binding_arguments][x-match]=all';
298+
299+
$connection = Connection::fromDsn($dsn, [], $factory);
300+
$connection->publish('body');
301+
}
302+
276303
public function testItCanDisableTheSetup()
277304
{
278305
$factory = new TestAmqpFactory(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
8181
* * password: Password to use the connect to the AMQP service
8282
* * queues[name]: An array of queues, keyed by the name
8383
* * binding_keys: The binding keys (if any) to bind to this queue
84+
* * binding_arguments: Arguments to be used while binding the queue.
8485
* * flags: Queue flags (Default: AMQP_DURABLE)
8586
* * arguments: Extra arguments
8687
* * exchange:
@@ -349,7 +350,7 @@ private function setupExchangeAndQueues(): void
349350
foreach ($this->queuesOptions as $queueName => $queueConfig) {
350351
$this->queue($queueName)->declareQueue();
351352
foreach ($queueConfig['binding_keys'] ?? [null] as $bindingKey) {
352-
$this->queue($queueName)->bind($this->exchangeOptions['name'], $bindingKey);
353+
$this->queue($queueName)->bind($this->exchangeOptions['name'], $bindingKey, $queueConfig['binding_arguments'] ?? []);
353354
}
354355
}
355356
}

0 commit comments

Comments
 (0)