1

We are using cloudformation template to create multiple EC2 instances. We have Auto scaling and ELB defined. Each EC2 instance runs with its own Tomcat server and a web application. We connect to SQS to pull messages and write to RDS database from this web app.

Problem statement - We do not want both EC2 instances pulling the same message from SQS and writing to RDS. Could you please direct me on how to make this process efficient?

uma
  • 35
  • 5
  • Possible duplicate of [What is a good practice to achieve the "Exactly-once delivery" behavior with Amazon SQS?](http://stackoverflow.com/questions/13484845/what-is-a-good-practice-to-achieve-the-exactly-once-delivery-behavior-with-ama) – Mark B Feb 01 '16 at 22:26

1 Answers1

0

Your question is reasonable, check out an explanation below.

Immediately after the component receives the message, the message is still in the queue. In order to prevent a situation you described, Amazon SQS blocks them with a visibility timeout, which is a period of time during which Amazon SQS prevents other consuming components from receiving and processing that message. Once your instance processed a message it should invoke a command that deletes a message from the queue. If for some reason, instance didn't finish a job during visibility timeout, the message becomes available for other instances again.

You can find more information here: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html

Flexo
  • 87,323
  • 22
  • 191
  • 272
Vladimir Mukhin
  • 577
  • 2
  • 7