Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SQS How can I reset a message's ReceiveCount

For various reasons my consumer on AWS sometimes reads a few messages from an SQS queue and decides to put some of them back in the queue to be processed later.

The way I do that is by setting their VisibilityTimeout to 0 which makes them immediately visible to other consumers. This is documented here.

The problem is that after doing that a few times, the message's ReceiveCount reaches the maxReceiveCount which causes the message to be moved to the DLQ. I'm wondering if I can somehow reset the message's ReceiveCount to avoid that.

The only option I can currently think of is to just send a copy of the message back to the beginning of the queue and deleting the original message.

like image 486
user972014 Avatar asked Oct 22 '25 06:10

user972014


1 Answers

I'm wondering if I can somehow reset the message's ReceiveCount to avoid that.

Sadly, you can't reset it as you its automatically managed by SQS. You have no control over it.

If you don't want to use multiple SQS, one for different purpose and consumer, the only solution I can think of is to simply increase maxReceiveCount to account for those extra reads. So if you know that your messages will be read and returned to the queue, let say 5 times, then increase your maxReceiveCount to 8 for instances. This will mean that if the message is read 3 times more then expected, there is something wrong with it.

like image 196
Marcin Avatar answered Oct 24 '25 20:10

Marcin