Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ protected function getExchangeConfiguration()
$node = new ArrayNodeDefinition('exchange_options');

return $node
->isRequired()
->children()
->scalarNode('name')->isRequired()->end()
->scalarNode('type')->isRequired()->end()
Expand All @@ -216,6 +215,7 @@ protected function getExchangeConfiguration()
->booleanNode('auto_delete')->defaultValue(false)->end()
->booleanNode('internal')->defaultValue(false)->end()
->booleanNode('nowait')->defaultValue(false)->end()
->booleanNode('declare')->defaultValue(true)->end()
->variableNode('arguments')->defaultNull()->end()
->scalarNode('ticket')->defaultNull()->end()
->end()
Expand Down
7 changes: 7 additions & 0 deletions DependencyInjection/OldSoundRabbitMqExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ protected function loadProducers()
$definition = new Definition($producer['class']);
$definition->addTag('old_sound_rabbit_mq.base_amqp');
$definition->addTag('old_sound_rabbit_mq.producer');
//this producer doesn't define an exchange -> using AMQP Default
if (!isset($producer['exchange_options'])) {
$producer['exchange_options']['name'] = '';
$producer['exchange_options']['type'] = 'direct';
$producer['exchange_options']['passive'] = true;
$producer['exchange_options']['declare'] = false;
}
$definition->addMethodCall('setExchangeOptions', array($this->normalizeArgumentKeys($producer['exchange_options'])));
//this producer doesn't define a queue
if (!isset($producer['queue_options'])) {
Expand Down
31 changes: 17 additions & 14 deletions RabbitMq/BaseAmqp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ abstract class BaseAmqp
'internal' => false,
'nowait' => false,
'arguments' => null,
'ticket' => null
'ticket' => null,
'declare' => true,
);

protected $queueOptions = array(
Expand Down Expand Up @@ -96,7 +97,7 @@ public function setChannel(AMQPChannel $ch)
*/
public function setExchangeOptions(array $options = array())
{
if (empty($options['name'])) {
if (!isset($options['name'])) {
throw new \InvalidArgumentException('You must provide an exchange name');
}

Expand Down Expand Up @@ -127,18 +128,20 @@ public function setRoutingKey($routingKey)

protected function exchangeDeclare()
{
$this->getChannel()->exchange_declare(
$this->exchangeOptions['name'],
$this->exchangeOptions['type'],
$this->exchangeOptions['passive'],
$this->exchangeOptions['durable'],
$this->exchangeOptions['auto_delete'],
$this->exchangeOptions['internal'],
$this->exchangeOptions['nowait'],
$this->exchangeOptions['arguments'],
$this->exchangeOptions['ticket']);

$this->exchangeDeclared = true;
if ($this->exchangeOptions['declare']) {
$this->getChannel()->exchange_declare(
$this->exchangeOptions['name'],
$this->exchangeOptions['type'],
$this->exchangeOptions['passive'],
$this->exchangeOptions['durable'],
$this->exchangeOptions['auto_delete'],
$this->exchangeOptions['internal'],
$this->exchangeOptions['nowait'],
$this->exchangeOptions['arguments'],
$this->exchangeOptions['ticket']);

$this->exchangeDeclared = true;
}
}

protected function queueDeclare()
Expand Down
8 changes: 8 additions & 0 deletions Tests/DependencyInjection/Fixtures/no_exchange_options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
old_sound_rabbit_mq:

connections:
default:

producers:
producer:
connection: default
22 changes: 22 additions & 0 deletions Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testFooProducerDefinition()
'nowait' => true,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -114,6 +115,7 @@ public function testDefaultProducerDefinition()
'nowait' => false,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -153,6 +155,7 @@ public function testFooConsumerDefinition()
'nowait' => true,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -204,6 +207,7 @@ public function testDefaultConsumerDefinition()
'nowait' => false,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -279,6 +283,7 @@ public function testMultipleConsumerDefinition()
'nowait' => false,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -343,6 +348,7 @@ public function testFooAnonConsumerDefinition()
'nowait' => true,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -378,6 +384,7 @@ public function testDefaultAnonConsumerDefinition()
'nowait' => false,
'arguments' => null,
'ticket' => null,
'declare' => true,
)
)
),
Expand Down Expand Up @@ -499,6 +506,21 @@ public function testExchangeArgumentsAreArray()
$this->assertEquals(array('name' => 'bar'), $options[0]['arguments']);
}

public function testProducerWithoutExplicitExchangeOptionsConnectsToAMQPDefault()
{
$container = $this->getContainer('no_exchange_options.yml');

$definition = $container->getDefinition('old_sound_rabbit_mq.producer_producer');
$calls = $definition->getMethodCalls();
$this->assertEquals('setExchangeOptions', $calls[0][0]);
$options = $calls[0][1];

$this->assertEquals('', $options[0]['name']);
$this->assertEquals('direct', $options[0]['type']);
$this->assertEquals(false, $options[0]['declare']);
$this->assertEquals(true, $options[0]['passive']);
}

private function getContainer($file, $debug = false)
{
$container = new ContainerBuilder(new ParameterBag(array('kernel.debug' => $debug)));
Expand Down