amazon-sqs-java-messaging-lib icon indicating copy to clipboard operation
amazon-sqs-java-messaging-lib copied to clipboard

same sqs message consumed by multiple sqs-sdk clients & also message resulted in dead queue

Open niteshjcp opened this issue 7 years ago • 1 comments

We are using com.amazonaws:aws-java-sdk:1.9.6 & com.amazonaws:amazon-sqs-java-messaging-lib:1.0.3 libraries for consuming the messages from SQS. We use Spring JMSTemplate for consume the messages with CLIENT_ACKNOWLEDGE mode.

We noticed an issue where multiple consumers picked the same message & also the message moved to the dead queue on sqs. When we inquired with AWS SQS support team, Below is the response (in quotes) we received. Can you let us know if any configuration is missing & what kind of logging needs to be enabled to debug this issue ?

"After looking at logs, below is why the message was returned 5 times within 1 second.

For each ReceiveMessage call, I see a ChangeMessageVisibilityBatch call with visibility timeout set to 0. This call was putting the message back in available state right away, allowing other consumers to pick the message. Below is the caller of ChangeMessageVisibilityBatch call.

UserAgent: aws-sdk-java/1.11.18 Linux/3.10.0-693.11.6.el7.x86_64 Java_HotSpot(TM)_64-Bit_Server_VM/25.131-b11/1.8.0_131 /SQS Java Messaging Client v1.0

Look like, it is the same code making both calls (ReceiveMessage and ChangeMessageVisibilityBatch). In order to understand why these calls were made in the first place, I request you to enable debug logging in the code. For any other issues with the library, I recommend opening an issue in the github repo. Our team that manages the library will address them. "

niteshjcp avatar Sep 24 '18 19:09 niteshjcp

We are experiencing the same problem, the visibility timeout is set to 120 on our side. However using Spring with the concurrency setting:

DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setDestinationResolver(new DynamicDestinationResolver());
        factory.setConcurrency("3-20");
        factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);

with connectionFactory() being:

SQSConnectionFactory.builder()
                        .withRegion(Region.getRegion(Regions.EU_CENTRAL_1))
                        .withAWSCredentialsProvider(new DefaultAWSCredentialsProviderChain())
                        .build();

The end result is that the message is consumed at the exact same second by multiple Containers. If that message fails it will fail for all Containers sending the event to the deadletter queue.

We are using Spring 4.3.9 and amazon-sqs-java-messaging-lib-1.0.4.

kollikolli avatar Oct 12 '18 07:10 kollikolli