-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Messenger] [Amqp] delayed quorum queues #60298
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
base: 7.2
Are you sure you want to change the base?
[Messenger] [Amqp] delayed quorum queues #60298
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
I've already done it in a nodeJS project and it works well in production. async function createDelayedQueue(channel, exchange, queue, delay) {
const date = new Date().toISOString().split('T')[0];
const delayedQueue = `delay_${exchange}_${queue}_${delay}_${date}`;
const delayedExchange = 'delays';
const baseExpire = 24 * 60 * 60 * 1000;
await channel.assertQueue(delayedQueue, {
durable: true,
arguments: {
'x-message-ttl': delay,
'x-expires': delay + 60 * 1000 + baseExpire,
'x-dead-letter-exchange': exchange,
'x-dead-letter-routing-key': queue,
'x-queue-type': 'quorum'
}
});
await channel.bindQueue(delayedQueue, delayedExchange, delayedQueue);
return { delayedQueue, delayedExchange };
} |
This probably also affect 6.4, right? |
Yes, that's right |
Sorry, I've tried to change the base branch to 6.4 and by mistake it has added automatically the reviewers, feel free to leave 🙏 |
No worries, we can target 6.4 while merging this PR 👍 |
Hi there! Just a friendly ping to see if there's anything else needed on this PR or if it can be reviewed when you get a chance. Thanks a lot for your time! |
Hi everyone! |
src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php
Outdated
Show resolved
Hide resolved
As this is a new feature, it must target |
Well, I consider it as a bug fix, because is causing problems when you use symfony with quorum rabbitmq queues, but, for me it's not a problem target it to |
Hi,
Actually, these are two separate concepts: the queue's duration and the message's TTL. The second message will be dead-lettered to the final queue only after its own TTL expires, regardless of when the queue was created or when the first message entered it. The mechanism is exactly the same as the one already used today. The difference is that with classic queues, if you redeclare the queue, its expiration is refreshed. With quorum queues, this doesn't happen—so we must ensure that the queue lasts long enough for all its messages. That’s why I create a delay queue per day with a TTL of delay + 1 day: this way, we ensure messages are processed properly, and we can still clean up old queues.
This is not entirely accurate. You can set the default queue type for a RabbitMQ Virtual Host. That’s actually how I discovered this issue: in our setup, I’m not arguing whether this is a bug or a missing feature, and I’m OK with this being addressed in Symfony 7.4. My goal is simply to move the PR forward, because RabbitMQ is deprecating classic mirrored queues. In RabbitMQ 4,
This was actually the first solution I tried when we started migrating from Beanstalkd (which has native support for delayed messages, and is very simple to use). Unfortunately, this approach has a critical issue: delay queues process messages in order. If the first message has a delay of 5 minutes, and the second one only 5 seconds, the second one will wait for the first to expire before being processed. This is why Symfony Messenger creates one queue per delay duration. It avoids the head-of-line blocking problem that comes with FIFO processing in delay queues. As I said previously, we even have some services in Node.js that use the same pattern. They’ve been running smoothly for over 6 months, with quorum queues, no message loss, and proper queue cleanup. I know this is a complex topic to fully explain in a PR comment, and English is not my first language—so if anything is unclear, please let me know and I’ll try to explain it differently. Thanks again for your feedback and time. |
@miquel-angel thanks for your time answering my comments. I learn a lot. Big thanks for your contribution. I'm looking forward to your PR to be merged :D @OskarStark I edited my comment to remove inexact information. Thanks for the feedback. |
0480703
to
40d03f5
Compare
Hi, Thanks! |
dbef6d6
to
809fcd3
Compare
255a3a2
to
1768200
Compare
src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php
Outdated
Show resolved
Hide resolved
…nnectionTest.php Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
bc22479
to
6819d3b
Compare
As described in the issue: #57867 when we create delayed quorum queues this doesn't update the expire time.
I've first tried what is suggested by rabbit maintainers here: rabbitmq/rabbitmq-server#5894 (comment) but it doesn't supported either.
So the final solution is create a delayed quorum queue per day, with expire of one day + ttl + 10 seconds, with this approach, when you enqueue a message to a delayed queue, you'll be sure that all the delayed message of the same day will be in the same queue and this queue won't die before the last message is processed.
For example you delay a message with 10s delay at 10:00 of 2025-04-29, this will create a delayed queue named:
delay_test_test_delay_2025-04-29 with expire on 2025-04-30 at 10:10:10.
If another message comes at 23:59:59, it will go to the same queue, that is already created.
And in the next day will create a new queue for the 30th.