diff --git a/pkg/amqp-ext/Symfony/AmqpTransportFactory.php b/pkg/amqp-ext/Symfony/AmqpTransportFactory.php index 9e92c3835..c8c5f40fb 100644 --- a/pkg/amqp-ext/Symfony/AmqpTransportFactory.php +++ b/pkg/amqp-ext/Symfony/AmqpTransportFactory.php @@ -85,6 +85,11 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->booleanNode('lazy') ->defaultTrue() ->end() + ->enumNode('receive_method') + ->values(['basic_get', 'basic_consume']) + ->defaultValue('basic_get') + ->info('The receive strategy to be used. We suggest to use basic_consume as it is more performant. Though you need AMQP extension 1.9.1 or higher') + ->end() ; } diff --git a/pkg/amqp-ext/Tests/Symfony/AmqpTransportFactoryTest.php b/pkg/amqp-ext/Tests/Symfony/AmqpTransportFactoryTest.php index 69d96ce83..eafeaa96d 100644 --- a/pkg/amqp-ext/Tests/Symfony/AmqpTransportFactoryTest.php +++ b/pkg/amqp-ext/Tests/Symfony/AmqpTransportFactoryTest.php @@ -9,6 +9,7 @@ use Enqueue\Test\ClassExtensionTrait; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -54,6 +55,7 @@ public function testShouldAllowAddConfiguration() 'vhost' => '/', 'persisted' => false, 'lazy' => true, + 'receive_method' => 'basic_get', ], $config); } @@ -76,6 +78,47 @@ public function testShouldAllowAddConfigurationAsString() 'vhost' => '/', 'persisted' => false, 'lazy' => true, + 'receive_method' => 'basic_get', + ], $config); + } + + public function testThrowIfInvalidReceiveMethodIsSet() + { + $transport = new AmqpTransportFactory(); + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $transport->addConfiguration($rootNode); + $processor = new Processor(); + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The value "anInvalidMethod" is not allowed for path "foo.receive_method". Permissible values: "basic_get", "basic_consume"'); + $processor->process($tb->buildTree(), [[ + 'receive_method' => 'anInvalidMethod', + ]]); + } + + public function testShouldAllowChangeReceiveMethod() + { + $transport = new AmqpTransportFactory(); + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $transport->addConfiguration($rootNode); + $processor = new Processor(); + $config = $processor->process($tb->buildTree(), [[ + 'receive_method' => 'basic_consume', + ]]); + + $this->assertEquals([ + 'host' => 'localhost', + 'port' => 5672, + 'user' => 'guest', + 'pass' => 'guest', + 'vhost' => '/', + 'persisted' => false, + 'lazy' => true, + 'receive_method' => 'basic_consume', ], $config); } diff --git a/pkg/amqp-ext/Tests/Symfony/RabbitMqAmqpTransportFactoryTest.php b/pkg/amqp-ext/Tests/Symfony/RabbitMqAmqpTransportFactoryTest.php index 2f9b3492f..a553f9b01 100644 --- a/pkg/amqp-ext/Tests/Symfony/RabbitMqAmqpTransportFactoryTest.php +++ b/pkg/amqp-ext/Tests/Symfony/RabbitMqAmqpTransportFactoryTest.php @@ -61,6 +61,7 @@ public function testShouldAllowAddConfiguration() 'persisted' => false, 'delay_plugin_installed' => false, 'lazy' => true, + 'receive_method' => 'basic_get', ], $config); }