Skip to content

Commit 7c66302

Browse files
Added config option to allow disabling x-expires in getDelayQueueArguments
1 parent d6ae780 commit 7c66302

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,30 @@ by adding extra options.
148148
],
149149
```
150150

151+
When you want to disable x-expires from a delayed queue, then this is possible by adding extra option on queue `expire_delay_queue`.
152+
- When the `expire_delay_queue` option is omitted, it is considered to be true.
153+
- Useful for when you're using quorum queues, as they risk to delete the queue before the messages are moved to their destination queue.
154+
155+
```php
156+
'connections' => [
157+
// ...
158+
159+
'rabbitmq' => [
160+
// ...
161+
162+
'options' => [
163+
'queue' => [
164+
// ...
165+
166+
'expire_delay_queue' => false,
167+
],
168+
],
169+
],
170+
171+
// ...
172+
],
173+
```
174+
151175
### Horizon support
152176

153177
Starting with 8.0, this package supports [Laravel Horizon](https://laravel.com/docs/horizon) out of the box. Firstly,

src/Queue/QueueConfig.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class QueueConfig
3030

3131
protected bool $quorum = false;
3232

33+
protected bool $expireDelayQueue = true;
34+
3335
protected array $options = [];
3436

3537
/**
@@ -262,6 +264,21 @@ public function setOptions(array $options): QueueConfig
262264
return $this;
263265
}
264266

267+
/**
268+
* Returns &true;, if the delay queue should expire.
269+
*/
270+
public function hasExpireDelayQueue(): bool
271+
{
272+
return $this->expireDelayQueue;
273+
}
274+
275+
public function setExpireDelayQueue($expireDelayQueue): QueueConfig
276+
{
277+
$this->expireDelayQueue = $this->toBoolean($expireDelayQueue);
278+
279+
return $this;
280+
}
281+
265282
/**
266283
* Filters $value to boolean value
267284
*

src/Queue/QueueConfigFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ protected static function getOptionsFromConfig(QueueConfig $queueConfig, array $
6868
$queueConfig->setQuorum($quorum);
6969
}
7070

71+
// Feature: Enable/disable x-expires from delay queue.
72+
if (! is_null($expireDelayQueue = Arr::pull($queueOptions, 'expire_delay_queue'))) {
73+
$queueConfig->setExpireDelayQueue($expireDelayQueue);
74+
}
75+
7176
// All extra options not defined
7277
$queueConfig->setOptions($queueOptions);
7378
}

src/Queue/RabbitMQQueue.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,17 @@ protected function getQueueArguments(string $destination): array
626626
*/
627627
protected function getDelayQueueArguments(string $destination, int $ttl): array
628628
{
629-
return [
629+
$arguments = [
630630
'x-dead-letter-exchange' => $this->getExchange(),
631631
'x-dead-letter-routing-key' => $this->getRoutingKey($destination),
632632
'x-message-ttl' => $ttl,
633-
'x-expires' => $ttl * 2,
634633
];
634+
635+
if ($this->getRabbitMQConfig()->hasExpireDelayQueue()) {
636+
$arguments['x-expires'] = $ttl * 2;
637+
}
638+
639+
return $arguments;
635640
}
636641

637642
/**

0 commit comments

Comments
 (0)