Skip to content

Commit

Permalink
Merge pull request #70 from softonic/master
Browse files Browse the repository at this point in the history
Allow multiple queue bindings
  • Loading branch information
bschmitt authored May 13, 2020
2 parents f2102e3 + 1a8a1fe commit a571a54
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ public function setup()
$this->getProperty('queue_properties')
);

$this->channel->queue_bind(
$queue ?: $this->queueInfo[0],
$exchange,
$this->getProperty('routing')
);
foreach ((array) $this->getProperty('routing') as $routingKey) {
$this->channel->queue_bind(
$queue ?: $this->queueInfo[0],
$exchange,
$routingKey
);
}
}
// clear at shutdown
$this->connection->set_close_on_destruct(true);
Expand Down
48 changes: 48 additions & 0 deletions test/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,54 @@ public function testIfQueueGetsDeclaredAndBoundIfInConfig()

}

public function testIfQueueGetsDeclaredAndBoundToDifferentRoutingKeysIfInConfig()
{

$queueName = 'amqp-test';
$routing = [
'routing-test-1',
'routing-test-2',
];

$this->requestMock->mergeProperties([
'queue' => $queueName,
'queue_force_declare' => true,
'routing' => $routing
]);
$this->channelMock->shouldReceive('exchange_declare');
$this->requestMock->shouldReceive('connect');

$this->channelMock->shouldReceive('queue_declare')
->with(
$queueName,
$this->defaultConfig['queue_passive'],
$this->defaultConfig['queue_durable'],
$this->defaultConfig['queue_exclusive'],
$this->defaultConfig['queue_auto_delete'],
$this->defaultConfig['queue_nowait'],
$this->defaultConfig['queue_properties']
)
->andReturn([$queueName, 4])
->times(1);
$this->channelMock->shouldReceive('queue_bind')
->with(
$queueName,
$this->defaultConfig['exchange'],
$routing[0]
)
->times(1);
$this->channelMock->shouldReceive('queue_bind')
->with(
$queueName,
$this->defaultConfig['exchange'],
$routing[1]
)
->times(1);
$this->connectionMock->shouldReceive('set_close_on_destruct')->with(true)->times(1);
$this->requestMock->setup();

}

public function testQueueMessageCountShouldBeZeroIfQueueinfoIsNotSet()
{

Expand Down

0 comments on commit a571a54

Please sign in to comment.