Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: videlalvaro/RabbitMqBundle
base: 7825c18bdb
...
head fork: videlalvaro/RabbitMqBundle
compare: b475469914
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 4 files changed
  • 4 commit comments
  • 2 contributors
View
1  DependencyInjection/Configuration.php
@@ -41,6 +41,7 @@ public function getConfigTreeBuilder()
->useAttributeAsKey('key')
->prototype('array')
->append($this->getExchangeConfiguration())
+ ->append($this->getQueueConfiguration())
->children()
->scalarNode('connection')->defaultValue('default')->end()
->end()
View
7 DependencyInjection/OldSoundRabbitMqExtension.php
@@ -29,6 +29,8 @@ class OldSoundRabbitMqExtension extends Extension
private $channelIds = array();
+ private $config = array();
+
public function load(array $configs, ContainerBuilder $container)
{
$this->container = $container;
@@ -81,6 +83,11 @@ protected function loadProducers()
foreach ($this->config['producers'] as $key => $producer) {
$definition = new Definition('%old_sound_rabbit_mq.producer.class%');
$definition->addMethodCall('setExchangeOptions', array($producer['exchange_options']));
+ //this producer doesn't define a queue
+ if (!isset($producer['queue_options'])) {
+ $producer['queue_options']['name'] = null;
+ }
+ $definition->addMethodCall('setQueueOptions', array($producer['queue_options']));
$this->injectConnection($definition, $producer['connection']);
if ($this->collectorEnabled) {
$this->injectLoggedChannel($definition, $key, $producer['connection']);
View
33 RabbitMq/Producer.php
@@ -9,7 +9,8 @@
class Producer extends BaseAmqp
{
- protected $declared = false;
+ protected $exchangeDeclared = false;
+ protected $queueDeclared = false;
public function exchangeDeclare()
{
@@ -21,14 +22,38 @@ public function exchangeDeclare()
$this->exchangeOptions['auto_delete'],
$this->exchangeOptions['internal']);
- $this->declared = true;
+ $this->exchangeDeclared = true;
}
- public function publish($msgBody, $routingKey = '')
+ public function queueDeclare()
+ {
+ if (null !== $this->queueOptions['name']) {
+ list($queueName, ,) = $this->ch->queue_declare($this->queueOptions['name'], $this->queueOptions['passive'],
+ $this->queueOptions['durable'], $this->queueOptions['exclusive'],
+ $this->queueOptions['auto_delete'], $this->queueOptions['nowait'],
+ $this->queueOptions['arguments'], $this->queueOptions['ticket']);
+
+ $this->ch->queue_bind($queueName, $this->exchangeOptions['name'], $this->routingKey);
+
+ $this->queueDeclared = true;
+ }
+ }
+
+ public function setupProducer()
{
- if (!$this->declared) {
+ if (!$this->exchangeDeclared) {
$this->exchangeDeclare();
}
+
+ if (!$this->queueDeclared) {
+ $this->queueDeclare();
+ }
+ }
+
+ public function publish($msgBody, $routingKey = '')
+ {
+ $this->setupProducer();
+
$msg = new AMQPMessage($msgBody, array('content_type' => 'text/plain', 'delivery_mode' => 2));
$this->ch->basic_publish($msg, $this->exchangeOptions['name'], $routingKey);
}
View
16 Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php
@@ -63,6 +63,14 @@ public function testFooProducerDefinition()
'ticket' => null,
)
)
+ ),
+ array(
+ 'setQueueOptions',
+ array(
+ array(
+ 'name' => null,
+ )
+ )
)
),
$definition->getMethodCalls()
@@ -94,6 +102,14 @@ public function testDefaultProducerDefinition()
'ticket' => null,
)
)
+ ),
+ array(
+ 'setQueueOptions',
+ array(
+ array(
+ 'name' => null,
+ )
+ )
)
),
$definition->getMethodCalls()

Showing you all comments on commits in this comparison.

@igrizzli

This code will already bind empty routingKey because it's will be setted only in consumer command.

Can you use routingKey from "publish" method?

@videlalvaro

I don't understand your comment. queue_declare returns the queue name generated by RabbitMQ when the queue was created. That name could be the name you provided to queue_declare or an auto generated name by the broker if you passed an empty queue name

@igrizzli

In consumer you can define custom routingKey for queue, but in producer $this->routingKey will always be empty, so using $this->routingKey have no meaning.

What do you think about declaration of routingKeys in config?

@videlalvaro

I get it now. So yes, first this should be called bindingKey, having routingKey there is a bit confusing. And yes, it could be made as a new option in the config

Something went wrong with that request. Please try again.