Reputation: 1305
I created a basic non-FIFO queue, and put only 1 message on it. I retrieve the message using the following code:
ReceiveMessageRequest request = new ReceiveMessageRequest();
request.setQueueUrl(queueUrl);
request.setMaxNumberOfMessages(10);
request.withMessageAttributeNames("All");
ReceiveMessageResult result = sqsClient.receiveMessage(request);
List<Message> messages = result.getMessages();
messages.size() gives 3
They have:
Changing MaxNumberOfMessages
from 10 to 1 fixed it, but I want to receive in batch of 10 in the future.
Can someone explain why it is retrieving more message than it should?
Below is my queue configuration:
Default visibility timeout = 0
message retention = 4 days
max message size = 256kb
delivery delay = 0
receive message wait time = 0
no redrive policy
Upvotes: 0
Views: 345
Reputation: 13166
Details /complement to @Michael - sqlbot comment.
Setting the SQS visibility timeout to a small value are not going to fix your problem. You are going to hit the problem again. Use 30 seconds or more in order to allow your program to consume the message. (To cater for program crashes/unexpected program delay, you should create redrive policy to mitigate the issues.)
AWS has mentioned this in At-Least-Once Delivery
Amazon SQS stores copies of your messages on multiple servers for redundancy and high availability. On rare occasions, one of the servers that stores a copy of a message might be unavailable when you receive or delete a message.
If this occurs, the copy of the message will not be deleted on that unavailable server, and you might get that message copy again when you receive messages. You should design your applications to be idempotent (they should not be affected adversely when processing the same message more than once).
Upvotes: 2
Reputation: 1305
Changing Default Visibility Timeout
from 0 to 1 second fixed the issue
Upvotes: 0