Skip to content

Commit 7486f05

Browse files
committed
RPC Server queue_options
1 parent 3dd7076 commit 7486f05

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ protected function addRpcServers(ArrayNodeDefinition $node)
196196
->canBeUnset()
197197
->useAttributeAsKey('key')
198198
->prototype('array')
199+
->append($this->getQueueConfiguration())
199200
->children()
200201
->scalarNode('connection')->defaultValue('default')->end()
201202
->scalarNode('callback')->isRequired()->end()

DependencyInjection/OldSoundRabbitMqExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ protected function loadRpcServers()
330330
$server['qos_options']['global']
331331
));
332332
}
333+
if (array_key_exists('queue_options', $server)) {
334+
$definition->addMethodCall('setQueueOptions', array($server['queue_options']));
335+
}
333336
$this->container->setDefinition(sprintf('old_sound_rabbit_mq.%s_server', $key), $definition);
334337
}
335338
}

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ consumers:
304304
305305
From: http://www.rabbitmq.com/tutorials/tutorial-two-python.html
306306
307-
Be careful as implementing the fair dispatching introduce a latency that will hurt performance (see [this blogpost](http://www.rabbitmq.com/blog/2012/05/11/some-queuing-theory-throughput-latency-and-bandwidth/)). But implemeting it allow you to scale horizontally dynamically as the queue is increasing.
307+
Be careful as implementing the fair dispatching introduce a latency that will hurt performance (see [this blogpost](http://www.rabbitmq.com/blog/2012/05/11/some-queuing-theory-throughput-latency-and-bandwidth/)). But implemeting it allow you to scale horizontally dynamically as the queue is increasing.
308308
You should evaluate, as the blogpost reccommand, the right value of prefetch_size accordingly with the time taken to process each message and your network performance.
309309
310310
With RabbitMqBundle, you can configure that qos_options per consumer like that:
@@ -385,8 +385,11 @@ rpc_servers:
385385
connection: default
386386
callback: random_int_server
387387
qos_options: {prefetch_size: 0, prefetch_count: 1, global: false}
388+
queue_options: {name: random_int_queue, durable: false, auto_delete: true}
388389
```
389390
391+
*For a full configuration reference please use the `php app/console config:dump-reference old_sound_rabbit_mq` command.*
392+
390393
Here we have a very useful server: it returns random integers to its clients. The callback used to process the request will be the __random\_int\_server__ service. Now let's see how to invoke it from our controllers.
391394
392395
First we have to start the server from the command line:

Tests/DependencyInjection/Fixtures/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,8 @@ old_sound_rabbit_mq:
148148

149149
default_server:
150150
callback: default_server.callback
151+
152+
server_with_queue_options:
153+
callback: server_with_queue_options.callback
154+
queue_options:
155+
name: "server_with_queue_options-queue"

Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,34 @@ public function testDefaultRpcServerDefinition()
468468
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass());
469469
}
470470

471+
public function testRpcServerWithQueueOptionsDefinition()
472+
{
473+
$container = $this->getContainer('test.yml');
474+
475+
$this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server'));
476+
$definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server');
477+
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default');
478+
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options');
479+
$this->assertEquals(array(
480+
array('initServer', array('server_with_queue_options')),
481+
array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))),
482+
array('setQueueOptions', array(array(
483+
'name' => 'server_with_queue_options-queue',
484+
'passive' => false,
485+
'durable' => true,
486+
'exclusive' => false,
487+
'auto_delete' => false,
488+
'nowait' => false,
489+
'arguments' => null,
490+
'ticket' => null,
491+
'routing_keys' => array(),
492+
))),
493+
),
494+
$definition->getMethodCalls()
495+
);
496+
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass());
497+
}
498+
471499
public function testHasCollectorWhenChannelsExist()
472500
{
473501
$container = $this->getContainer('collector.yml');

0 commit comments

Comments
 (0)