Skip to content

Commit 5a8d35d

Browse files
authored
Added new arguments parameter in queueBind() method for MultipleConsumers (#35)
1 parent c836a69 commit 5a8d35d

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

RabbitMq/MultipleConsumer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ protected function queueDeclare()
8080

8181
if (isset($options['routing_keys']) && count($options['routing_keys']) > 0) {
8282
foreach ($options['routing_keys'] as $routingKey) {
83-
$this->queueBind($queueName, $this->exchangeOptions['name'], $routingKey);
83+
$this->queueBind($queueName, $this->exchangeOptions['name'], $routingKey, $options['arguments'] ?? []);
8484
}
8585
} else {
86-
$this->queueBind($queueName, $this->exchangeOptions['name'], $this->routingKey);
86+
$this->queueBind($queueName, $this->exchangeOptions['name'], $this->routingKey, $options['arguments'] ?? []);
8787
}
8888
}
8989

Tests/RabbitMq/MultipleConsumerTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,58 @@ public function processMessageProvider()
200200
);
201201
}
202202

203+
/**
204+
* @dataProvider queueBindingRoutingKeyProvider
205+
*/
206+
public function testShouldConsiderQueueArgumentsOnQueueDeclaration($routingKeysOption, $expectedRoutingKey)
207+
{
208+
$queueName = 'test-queue-name';
209+
$exchangeName = 'test-exchange-name';
210+
$expectedArgs = ['test-argument' => ['S', 'test-value']];
211+
212+
$this->amqpChannel->expects($this->any())
213+
->method('getChannelId')->willReturn(0);
214+
215+
$this->amqpChannel->expects($this->any())
216+
->method('queue_declare')
217+
->willReturn([$queueName, 5, 0]);
218+
219+
220+
$this->multipleConsumer->setExchangeOptions([
221+
'declare' => false,
222+
'name' => $exchangeName,
223+
'type' => 'topic']);
224+
225+
$this->multipleConsumer->setQueues([
226+
$queueName => [
227+
'passive' => true,
228+
'durable' => true,
229+
'exclusive' => true,
230+
'auto_delete' => true,
231+
'nowait' => true,
232+
'arguments' => $expectedArgs,
233+
'ticket' => null,
234+
'routing_keys' => $routingKeysOption]
235+
]);
236+
237+
$this->multipleConsumer->setRoutingKey('test-routing-key');
238+
239+
// we assert that arguments are passed to the bind method
240+
$this->amqpChannel->expects($this->once())
241+
->method('queue_bind')
242+
->with($queueName, $exchangeName, $expectedRoutingKey, false, $expectedArgs);
243+
244+
$this->multipleConsumer->setupFabric();
245+
}
246+
247+
public function queueBindingRoutingKeyProvider()
248+
{
249+
return array(
250+
array(array(), 'test-routing-key'),
251+
array(array('test-routing-key-2'), 'test-routing-key-2'),
252+
);
253+
}
254+
203255
/**
204256
* Preparing AMQP Connection
205257
*

0 commit comments

Comments
 (0)