Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger][AMQP] Support for RabbitMQ Quorum Queues in delayed queues #46254

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

Closed
JanMikes opened this issue May 4, 2022 · 9 comments
Closed

Comments

@JanMikes
Copy link

JanMikes commented May 4, 2022

Description

Hi!

Quorum Queues were introduced in RabbitMQ 3.8.0.
Since 3.10.0 it supports x-message-ttl which is used by Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection::createDelayQueue() - it was basically the missing piece to be able to use quorum queues for delayed queues.

Right now there is no way to configure messenger so it creates delayed queues as quorum.

Quote from the documentation:

To declare a quorum queue set the x-queue-type queue argument to quorum (the default is classic). This argument must be provided by a client at queue declaration time; it cannot be set or changed using a policy. This is because policy definition or applicable policy can be changed dynamically but queue type cannot. It must be specified at the time of declaration.

Apart of the x-queue-type it would be great to be able to pass more arguments for delyed queues, like x-quorum-initial-group-size.

Example

No response

@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@JanMikes
Copy link
Author

JanMikes commented Nov 7, 2022

I am not 100% sure, but I think this has not been implemented already.

@carsonbot carsonbot removed the Stalled label Nov 7, 2022
@fwolfsjaeger
Copy link
Contributor

Shouldn't it be easy to add this by extending \Symfony\Component\Messenger\Bridge\Amqp\Transport\Connection::createDelayQueue() with:

if (isset($this->exchangeOptions['arguments'])) {
    $this->amqpExchange->setArguments($this->exchangeOptions['arguments']);
}

@fwolfsjaeger
Copy link
Contributor

Close enough, it worked for me like this:

    private function createDelayQueue(int $delay, ?string $routingKey, bool $isRetryAttempt): \AMQPQueue
    {
        $queue = $this->amqpFactory->createQueue($this->channel());
        $queue->setName($this->getRoutingKeyForDelay($delay, $routingKey, $isRetryAttempt));
        $queue->setFlags(\AMQP_DURABLE);

        $arguments = [
            'x-message-ttl' => $delay,
            // delete the delay queue 10 seconds after the message expires
            // publishing another message redeclares the queue which renews the lease
            'x-expires' => $delay + 10000,
            // message should be broadcasted to all consumers during delay, but to only one queue during retry
            // empty name is default direct exchange
            'x-dead-letter-exchange' => $isRetryAttempt ? '' : $this->exchangeOptions['name'],
            // after being released from to DLX, make sure the original routing key will be used
            // we must use an empty string instead of null for the argument to be picked up
            'x-dead-letter-routing-key' => $routingKey ?? '',
        ];

        if (!empty($this->queuesOptions[$routingKey]['arguments'])) {
            $arguments = array_merge($this->queuesOptions[$routingKey]['arguments'], $arguments);
        }

        $queue->setArguments($arguments);

        return $queue;
    }

@fwolfsjaeger
Copy link
Contributor

I can create a PR tomorrow ...

@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@freswa
Copy link

freswa commented Nov 2, 2023

@carsonbot This is still a valid issue until #48603 has been merged.

@xabbuh xabbuh reopened this Nov 2, 2023
nicolas-grekas added a commit that referenced this issue Feb 7, 2024
…lay queues (Thomas Beaujean)

This PR was merged into the 7.1 branch.

Discussion
----------

[Messenger][Amqp] Add config option 'arguments' for delay queues

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #44186 #46254
| License       | MIT
| Doc PR        | symfony/symfony-docs#17553

Hi, this PR to allow to add extra arguments to the amqp delay queues that are automatically created.

The use case:
- I do not know in advance the name of the queues (handled by env variables)
- The queues are created automatically by symfony if needed
- I need the deduplication plugin in both the queue and the associated delays queues (enabled with the x-message-deduplication argument)
- I do not want to rewrite all delay arguments, I just want to be able to add or rewrite some

The associated configuration in messenger.yaml
```
        transports:
            async:
                dsn: '%env(MESSENGER_DSN)%'
                options:
                    queues:
                        '%env(MESSENGER_ASYNC_QUEUE_NAME)%':
                            arguments:
                                x-queue-type: 'classic'
                                x-message-deduplication: true
                    delay:
                        arguments:
                            x-queue-type: 'classic'
                            x-message-deduplication: true
```

Commits
-------

94ee8a2 [Messenger] Add config option 'arguments' for delay queues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants