Skip to content

Commit 4edabc7

Browse files
authored
Merge pull request #118 from php-enqueue/bundle-add-amqp-receive-method-option
[amqp] Add 'receive_method' to amqp transport factory.
2 parents afecde0 + 0f9ae68 commit 4edabc7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Diff for: pkg/amqp-ext/Symfony/AmqpTransportFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public function addConfiguration(ArrayNodeDefinition $builder)
8585
->booleanNode('lazy')
8686
->defaultTrue()
8787
->end()
88+
->enumNode('receive_method')
89+
->values(['basic_get', 'basic_consume'])
90+
->defaultValue('basic_get')
91+
->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')
92+
->end()
8893
;
8994
}
9095

Diff for: pkg/amqp-ext/Tests/Symfony/AmqpTransportFactoryTest.php

+43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Enqueue\Test\ClassExtensionTrait;
1010
use PHPUnit\Framework\TestCase;
1111
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
12+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1213
use Symfony\Component\Config\Definition\Processor;
1314
use Symfony\Component\DependencyInjection\ContainerBuilder;
1415
use Symfony\Component\DependencyInjection\Reference;
@@ -54,6 +55,7 @@ public function testShouldAllowAddConfiguration()
5455
'vhost' => '/',
5556
'persisted' => false,
5657
'lazy' => true,
58+
'receive_method' => 'basic_get',
5759
], $config);
5860
}
5961

@@ -76,6 +78,47 @@ public function testShouldAllowAddConfigurationAsString()
7678
'vhost' => '/',
7779
'persisted' => false,
7880
'lazy' => true,
81+
'receive_method' => 'basic_get',
82+
], $config);
83+
}
84+
85+
public function testThrowIfInvalidReceiveMethodIsSet()
86+
{
87+
$transport = new AmqpTransportFactory();
88+
$tb = new TreeBuilder();
89+
$rootNode = $tb->root('foo');
90+
91+
$transport->addConfiguration($rootNode);
92+
$processor = new Processor();
93+
94+
$this->expectException(InvalidConfigurationException::class);
95+
$this->expectExceptionMessage('The value "anInvalidMethod" is not allowed for path "foo.receive_method". Permissible values: "basic_get", "basic_consume"');
96+
$processor->process($tb->buildTree(), [[
97+
'receive_method' => 'anInvalidMethod',
98+
]]);
99+
}
100+
101+
public function testShouldAllowChangeReceiveMethod()
102+
{
103+
$transport = new AmqpTransportFactory();
104+
$tb = new TreeBuilder();
105+
$rootNode = $tb->root('foo');
106+
107+
$transport->addConfiguration($rootNode);
108+
$processor = new Processor();
109+
$config = $processor->process($tb->buildTree(), [[
110+
'receive_method' => 'basic_consume',
111+
]]);
112+
113+
$this->assertEquals([
114+
'host' => 'localhost',
115+
'port' => 5672,
116+
'user' => 'guest',
117+
'pass' => 'guest',
118+
'vhost' => '/',
119+
'persisted' => false,
120+
'lazy' => true,
121+
'receive_method' => 'basic_consume',
79122
], $config);
80123
}
81124

Diff for: pkg/amqp-ext/Tests/Symfony/RabbitMqAmqpTransportFactoryTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function testShouldAllowAddConfiguration()
6161
'persisted' => false,
6262
'delay_plugin_installed' => false,
6363
'lazy' => true,
64+
'receive_method' => 'basic_get',
6465
], $config);
6566
}
6667

0 commit comments

Comments
 (0)