From d22e8c9e32a07cd7772ecfdd96073a4453ff8722 Mon Sep 17 00:00:00 2001 From: Xavi Aparicio Date: Thu, 4 Jul 2019 14:06:24 +0200 Subject: [PATCH 1/4] Allow multiple queue bindings --- src/Request.php | 20 +++++++++++++----- test/RequestTest.php | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/Request.php b/src/Request.php index d2f0c91..39dc030 100644 --- a/src/Request.php +++ b/src/Request.php @@ -121,11 +121,21 @@ public function setup() $this->getProperty('queue_properties') ); - $this->channel->queue_bind( - $queue ?: $this->queueInfo[0], - $exchange, - $this->getProperty('routing') - ); + if (is_array($this->getProperty('routing'))) { + foreach ($this->getProperty('routing') as $routingKey) { + $this->channel->queue_bind( + $queue ?: $this->queueInfo[0], + $exchange, + $routingKey + ); + } + } else { + $this->channel->queue_bind( + $queue ?: $this->queueInfo[0], + $exchange, + $this->getProperty('routing') + ); + } } // clear at shutdown $this->connection->set_close_on_destruct(true); diff --git a/test/RequestTest.php b/test/RequestTest.php index 5617d9a..2623c53 100644 --- a/test/RequestTest.php +++ b/test/RequestTest.php @@ -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() { From 8af32663381264054eb3ab68478f278b763c5ec7 Mon Sep 17 00:00:00 2001 From: Xavi Aparicio Date: Thu, 4 Jul 2019 15:19:25 +0200 Subject: [PATCH 2/4] Allow multiple queue bindings --- src/Request.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Request.php b/src/Request.php index 39dc030..278d187 100644 --- a/src/Request.php +++ b/src/Request.php @@ -121,19 +121,11 @@ public function setup() $this->getProperty('queue_properties') ); - if (is_array($this->getProperty('routing'))) { - foreach ($this->getProperty('routing') as $routingKey) { - $this->channel->queue_bind( - $queue ?: $this->queueInfo[0], - $exchange, - $routingKey - ); - } - } else { + foreach ((array) $this->getProperty('routing') as $routingKey) { $this->channel->queue_bind( $queue ?: $this->queueInfo[0], $exchange, - $this->getProperty('routing') + $routingKey ); } } From aaddbad76c0908b6f0dac70efadecd3f7c414004 Mon Sep 17 00:00:00 2001 From: joskfg Date: Thu, 18 Jul 2019 10:14:47 +0200 Subject: [PATCH 3/4] Change vendor to allow use this package --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8038af9..ed4360a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "bschmitt/laravel-amqp", + "name": "softonic/laravel-amqp", "description": "AMQP wrapper for Laravel and Lumen to publish and consume messages", "keywords": [ "laravel", From 1a8a1fe7d27ecb917d957601ac5bbc5d4924a9d3 Mon Sep 17 00:00:00 2001 From: joskfg Date: Thu, 18 Jul 2019 10:27:34 +0200 Subject: [PATCH 4/4] Revert --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed4360a..8038af9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "softonic/laravel-amqp", + "name": "bschmitt/laravel-amqp", "description": "AMQP wrapper for Laravel and Lumen to publish and consume messages", "keywords": [ "laravel",