Skip to content

Commit bb2701d

Browse files
committed
Merge pull request #222 from Padam87/patch_rpc
RPC Server queue_options
2 parents 2c66d26 + 7486f05 commit bb2701d

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
@@ -201,6 +201,7 @@ protected function addRpcServers(ArrayNodeDefinition $node)
201201
->canBeUnset()
202202
->useAttributeAsKey('key')
203203
->prototype('array')
204+
->append($this->getQueueConfiguration())
204205
->children()
205206
->scalarNode('connection')->defaultValue('default')->end()
206207
->scalarNode('callback')->isRequired()->end()

DependencyInjection/OldSoundRabbitMqExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ protected function loadRpcServers()
332332
$server['qos_options']['global']
333333
));
334334
}
335+
if (array_key_exists('queue_options', $server)) {
336+
$definition->addMethodCall('setQueueOptions', array($server['queue_options']));
337+
}
335338
$this->container->setDefinition(sprintf('old_sound_rabbit_mq.%s_server', $key), $definition);
336339
}
337340
}

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
@@ -157,3 +157,8 @@ old_sound_rabbit_mq:
157157

158158
default_server:
159159
callback: default_server.callback
160+
161+
server_with_queue_options:
162+
callback: server_with_queue_options.callback
163+
queue_options:
164+
name: "server_with_queue_options-queue"

Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php

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

492+
public function testRpcServerWithQueueOptionsDefinition()
493+
{
494+
$container = $this->getContainer('test.yml');
495+
496+
$this->assertTrue($container->has('old_sound_rabbit_mq.server_with_queue_options_server'));
497+
$definition = $container->getDefinition('old_sound_rabbit_mq.server_with_queue_options_server');
498+
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default');
499+
$this->assertEquals((string) $definition->getArgument(1), 'old_sound_rabbit_mq.channel.server_with_queue_options');
500+
$this->assertEquals(array(
501+
array('initServer', array('server_with_queue_options')),
502+
array('setCallback', array(array(new Reference('server_with_queue_options.callback'), 'execute'))),
503+
array('setQueueOptions', array(array(
504+
'name' => 'server_with_queue_options-queue',
505+
'passive' => false,
506+
'durable' => true,
507+
'exclusive' => false,
508+
'auto_delete' => false,
509+
'nowait' => false,
510+
'arguments' => null,
511+
'ticket' => null,
512+
'routing_keys' => array(),
513+
))),
514+
),
515+
$definition->getMethodCalls()
516+
);
517+
$this->assertEquals('%old_sound_rabbit_mq.rpc_server.class%', $definition->getClass());
518+
}
519+
492520
public function testHasCollectorWhenChannelsExist()
493521
{
494522
$container = $this->getContainer('collector.yml');

0 commit comments

Comments
 (0)