Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon SQS: The same message is consumed by two current consumers

I have four current consumers listening to the same queue on Amazon AWS. When pulling message down from the queue, it appears sometimes the same message is consumed by two different consumers. Please see the log below:

18:01:46,515 [jmsContainer-2] DEBUG - Received message from the queue: ID:3698a927-930b-4d6a-aeca-f66922528792

18:02:12,825 [jmsContainer-3] DEBUG - Received message from the queue: ID:3698a927-930b-4d6a-aeca-f66922528792

I have a JMS container setup with 4 concurrent consumers. I have the visibility timeout set to 30s.

Since the message is received by container2, how come container3 is still able to access it?

Does JMS container do auto-acknowledgment before or after the execution of the listener method (handleMessage)?

like image 872
Gary Xue Avatar asked Mar 15 '16 22:03

Gary Xue


2 Answers

Amazon does not guarantee exactly once delivery with SQS. They guarantee "at least once" delivery. This is addressed in the FAQ https://aws.amazon.com/sqs/faqs/

You have to keep this in mind and design your system to gracefully handle duplicate message delivery.

like image 145
Mark B Avatar answered Oct 12 '22 13:10

Mark B


This is possible now with FIFO SQS queues. You can make sure exactly one client receives the message and then delete it while the message is in-flight

More information here:

https://aws.amazon.com/about-aws/whats-new/2016/11/amazon-sqs-introduces-fifo-queues-with-exactly-once-processing-and-lower-prices-for-standard-queues/

like image 3
Jagadish Kamath Avatar answered Oct 12 '22 14:10

Jagadish Kamath