Skip to content

Commit 25b93b3

Browse files
committed
add ability to change delay strategy
1 parent 4c1a27e commit 25b93b3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/AmqpConnector.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Enqueue\LaravelQueue;
44

5+
use Enqueue\AmqpTools\DelayStrategy;
56
use Enqueue\AmqpTools\DelayStrategyAware;
7+
use Enqueue\AmqpTools\RabbitMqDelayPluginDelayStrategy;
68
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
79
use Interop\Amqp\AmqpContext;
810

@@ -12,15 +14,25 @@ public function connect(array $config)
1214
{
1315
$queue = parent::connect($config);
1416

17+
$config = array_replace(['delay_strategy' => 'rabbitmq_dlx'], $config);
18+
19+
20+
1521
/** @var AmqpContext $amqpContext */
1622
$amqpContext = $queue->getPsrContext();
1723
if (false == $amqpContext instanceof AmqpContext) {
1824
throw new \LogicException(sprintf('The context must be instance of "%s" but got "%s"', AmqpContext::class, get_class($queue->getPsrContext())));
1925
}
2026

21-
if ($amqpContext instanceof DelayStrategyAware) {
27+
if ($amqpContext instanceof DelayStrategyAware && 'rabbitmq_dlx' == $config['delay_strategy']) {
2228
$amqpContext->setDelayStrategy(new RabbitMqDlxDelayStrategy());
2329
}
30+
if ($amqpContext instanceof DelayStrategyAware && 'rabbitmq_delay_plugin' == $config['delay_strategy']) {
31+
$amqpContext->setDelayStrategy(new RabbitMqDelayPluginDelayStrategy());
32+
}
33+
if ($amqpContext instanceof DelayStrategyAware && $config['delay_strategy'] instanceof DelayStrategy) {
34+
$amqpContext->setDelayStrategy($config['delay_strategy']);
35+
}
2436

2537
return $queue;
2638
}

0 commit comments

Comments
 (0)