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

Skip to content

[Messenger] Allow SQS to handle its own retry/DLQ #60754

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

maxbaldanza
Copy link
Contributor

@maxbaldanza maxbaldanza commented Jun 10, 2025

Allow SQS to handle retries rather then handling this by Symfony.
This allows applications to use the retry strategy from SQS rather then Symfony.
The default is for the message to be deleted from SQS at which point Symfony
will handle the retry by then adding back in to the queue.
If delete_on_rejection is set to false instead it will change the message
visibility of the message on SQS and thus SQS to handle the retry mechanism

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #45104
License MIT

As mentioned on the linked issue this has a number of benefits but mainly

  • The consumer no longer needs to be able to send messages into the queue.
  • Less chance of message loss

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "7.4 for features".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@@ -101,6 +102,7 @@ public function __destruct()
* * wait_time: long polling duration in seconds (Default: 20)
* * poll_timeout: amount of seconds the transport should wait for new message
* * visibility_timeout: amount of seconds the message won't be visible
* * delete_on_rejection: Whether to delete message on rejection or allow SQS to handle retries. (Default: true). If set to false then the `retry_strategy` should be set to `max_retries: 0`
Copy link
Contributor Author

@maxbaldanza maxbaldanza Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should throw an error if setting delete_on_rejection and the retry_strategy doesn't have max_retries set as 0 as this option should only be used if SQS is fully responsible for the retries/DLQ but we don't have access to that so was hoping documentation is enough to cover that.

Would love to hear thoughts here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should it be set to 0? what happens if that's not set as documented?

Copy link
Contributor Author

@maxbaldanza maxbaldanza Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd end up with a duplicate message in SQS.
When the message is rejected we'd change the visibility of the message meaning it will reappear in the queue after the timeout period but then the SendFailedMessageForRetryListener would then also resend the message back to SQS meaning you'd end up with 2 of the same messages in SQS.

If the transports had access to the retry strategy then an exception could be thrown if this configuration was setup but I didn't want to introduce adding the retry strategy to transports before first making sure that was the route to take. You may also have a better way to solve that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting max_retries to 0 won't disable resending another message to the queue as RecoverableExceptionInterface and some other cases are always retried even if max_retries is 0 or reached its max.

Copy link
Contributor Author

@maxbaldanza maxbaldanza Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes your right @deguif, thanks for pointing that out 🙌

I've just pushed a change that should solve that, instead now the transport checks if the message is being resent using the RedeliveryStamp and if so we don't send it to the sender.

Let me know what you think

@maxbaldanza maxbaldanza changed the title [Messenger] Allow SQS to handle it's own retry/DLQ [Messenger] Allow SQS to handle its own retry/DLQ Jun 11, 2025
@maxbaldanza
Copy link
Contributor Author

Hey!

Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "7.4 for features". Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

Thanks Carsonbot I fixed the mistake

Allow SQS to handle retries rather then handling this by Symfony.
This allows applications to use the retry strategy from SQS rather then Symfony.
The default is for the message to be deleted from SQS at which point Symfony
will handle the retry by deleting and then adding back in to the queue.
If `delete_on_rejection` is set to `false` instead it will change the message
visibility of the message on SQS and thus SQS to handle the retry mechanism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symfony SQS Transport not compatible with SQS-DLQs
4 participants