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

Commit

Permalink
Merge 74b522e into 5db745c
Browse files Browse the repository at this point in the history
  • Loading branch information
llupa committed Jan 17, 2020
2 parents 5db745c + 74b522e commit 03641e2
Show file tree
Hide file tree
Showing 5 changed files with 29 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 @@ -81,6 +81,10 @@ Full configuration options:
vhost: guest
console_url: 'http://localhost:55672/api'
factory_class: \Enqueue\AmqpLib\AmqpConnectionFactory
# Use this option to specify the delay strategy
# If you want to completely ignore this you can set it to null
delay_strategy: null
consumers:
# If set to true, SwiftMailerConsumer and LoggerConsumer will be registered as services
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
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public function getConfigTreeBuilder()
->defaultValue(AmqpConnectionFactory::class)
->info('This option defines an AMQP connection factory to be used to establish a connection with RabbitMQ.')
->end()
->scalarNode('delay_strategy')
->isRequired()
->defaultNull()
->info('This option defines the delay strategy to use in case an AMQP connection factory is of DelayStrategyAware type. Defaults to null if should be ignored.')
->end()
->end()
->end()
->end()
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 (null !== $connection['delay_strategy'] && $container->has($connection['delay_strategy'])) {
$container->setAlias('sonata.notification.backend.rabbitmq.delay_strategy', $connection['delay_strategy']);
}

$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 03641e2

Please sign in to comment.