Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Merge 668c153 into 5db745c
Browse files Browse the repository at this point in the history
  • Loading branch information
llupa committed Jan 21, 2020
2 parents 5db745c + 668c153 commit e9905c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion docs/reference/advanced_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ Full configuration options:
pass: guest
vhost: guest
console_url: 'http://localhost:55672/api'
# By default the RabbitMQ configuration uses a DelayStrategyAware connection factory.
# The default connection is assigned a RabbitMqDlxDelayStrategy object.
# To specify your own custom delay strategy override the 'sonata.notification.backend.rabbitmq.delay_strategy' service
factory_class: \Enqueue\AmqpLib\AmqpConnectionFactory
consumers:
Expand Down Expand Up @@ -141,4 +145,3 @@ run `composer require enqueue/amqp-ext:^0.8` and change `factory_class` option i
.. _`enqueue/amqp-lib`: https://github.com/php-enqueue/enqueue-dev/blob/master/docs/transport/amqp_lib.md
.. _`enqueue/amqp-ext`: https://github.com/php-enqueue/enqueue-dev/blob/master/docs/transport/amqp_ext.md
.. _`enqueue/amqp-bunny`: https://github.com/php-enqueue/enqueue-dev/blob/master/docs/transport/amqp_bunny.md

16 changes: 13 additions & 3 deletions src/Backend/AMQPBackendDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sonata\NotificationBundle\Backend;

use Enqueue\AmqpTools\DelayStrategy;
use Enqueue\AmqpTools\DelayStrategyAware;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Guzzle\Http\Client as GuzzleClient;
use Interop\Amqp\AmqpConnectionFactory;
use Interop\Amqp\AmqpContext;
Expand Down Expand Up @@ -62,6 +62,11 @@ class AMQPBackendDispatcher extends QueueBackendDispatcher
*/
private $context;

/**
* @var DelayStrategy
*/
private $delayStrategy = null;

/**
* @param string $defaultQueue
*/
Expand Down Expand Up @@ -129,8 +134,8 @@ final public function getContext()
'vhost' => $this->settings['vhost'],
]);

if ($factory instanceof DelayStrategyAware) {
$factory->setDelayStrategy(new RabbitMqDlxDelayStrategy());
if ($factory instanceof DelayStrategyAware && $this->delayStrategy instanceof DelayStrategy) {
$factory->setDelayStrategy($this->delayStrategy);
}

$this->context = $factory->createContext();
Expand Down Expand Up @@ -269,6 +274,11 @@ public function initialize()
{
}

public function setDelayStrategy(DelayStrategy $delayStrategy): void
{
$this->delayStrategy = $delayStrategy;
}

/**
* Calls the rabbitmq management api /api/<vhost>/queues endpoint to list the available queues.
*
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/SonataNotificationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ protected function configureRabbitmq(ContainerBuilder $container, array $config)
throw new \RuntimeException('You need to specify a valid default queue for the rabbitmq backend!');
}

if (class_exists('\Enqueue\AmqpTools\RabbitMqDlxDelayStrategy')) {
$container->setDefinition('sonata.notification.backend.rabbitmq.delay_strategy', new Definition(\Enqueue\AmqpTools\RabbitMqDlxDelayStrategy::class));
}

$container->getDefinition('sonata.notification.backend.rabbitmq')
->replaceArgument(0, $connection)
->replaceArgument(1, $queues)
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/backend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<argument/>
<argument/>
<argument/>
<call method="setDelayStrategy">
<argument type="service" id="sonata.notification.backend.rabbitmq.delay_strategy" on-invalid="ignore"/>
</call>
</service>
</services>
</container>

0 comments on commit e9905c1

Please sign in to comment.