Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added config option to allow disabling x-expires in getDelayQueueArguments #606

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ by adding extra options.
],
```

When you want to disable x-expires from a delayed queue, then this is possible by adding extra option on queue `expire_delay_queue`.
- When the `expire_delay_queue` option is omitted, it is considered to be true.
- Useful for when you're using quorum queues, as they risk to delete the queue before the messages are moved to their destination queue.

```php
'connections' => [
// ...

'rabbitmq' => [
// ...

'options' => [
'queue' => [
// ...

'expire_delay_queue' => false,
],
],
],

// ...
],
```

### Horizon support

Starting with 8.0, this package supports [Laravel Horizon](https://laravel.com/docs/horizon) out of the box. Firstly,
Expand Down
17 changes: 17 additions & 0 deletions src/Queue/QueueConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class QueueConfig

protected bool $quorum = false;

protected bool $expireDelayQueue = true;

protected array $options = [];

/**
Expand Down Expand Up @@ -262,6 +264,21 @@ public function setOptions(array $options): QueueConfig
return $this;
}

/**
* Returns &true;, if the delay queue should expire.
*/
public function hasExpireDelayQueue(): bool
{
return $this->expireDelayQueue;
}

public function setExpireDelayQueue($expireDelayQueue): QueueConfig
{
$this->expireDelayQueue = $this->toBoolean($expireDelayQueue);

return $this;
}

/**
* Filters $value to boolean value
*
Expand Down
5 changes: 5 additions & 0 deletions src/Queue/QueueConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ protected static function getOptionsFromConfig(QueueConfig $queueConfig, array $
$queueConfig->setQuorum($quorum);
}

// Feature: Enable/disable x-expires from delay queue.
if (! is_null($expireDelayQueue = Arr::pull($queueOptions, 'expire_delay_queue'))) {
$queueConfig->setExpireDelayQueue($expireDelayQueue);
}

// All extra options not defined
$queueConfig->setOptions($queueOptions);
}
Expand Down
9 changes: 7 additions & 2 deletions src/Queue/RabbitMQQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,17 @@ protected function getQueueArguments(string $destination): array
*/
protected function getDelayQueueArguments(string $destination, int $ttl): array
{
return [
$arguments = [
'x-dead-letter-exchange' => $this->getExchange(),
'x-dead-letter-routing-key' => $this->getRoutingKey($destination),
'x-message-ttl' => $ttl,
'x-expires' => $ttl * 2,
];

if ($this->getConfig()->hasExpireDelayQueue()) {
$arguments['x-expires'] = $ttl * 2;
}

return $arguments;
}

/**
Expand Down