I am doing some operations which will publish messages to an SQS, a standard SQS, not a FIFO one. After that I am trying to receive both the messages from SQS and delete both of them. I have written the following code for receiving and deleting messages from SQS.
private ReceiveMessageRequest getReceiveMessageRequest() {
return new ReceiveMessageRequest(QUEUE_URL)
.withMaxNumberOfMessages(5);
}
private void deleteMessagesInIntegrationQueue(List<Message> messages) {
messages.forEach(
message -> testSQS.deleteMessage(new DeleteMessageRequest(QUEUE_URL, message.getReceiptHandle()))
);
}
List<Message> results = testSQS.receiveMessage(getReceiveMessageRequest()).getMessages();
SOPL(results);
deleteMessagesInQueue(results);
List<Message> newResults = testSQS.receiveMessage(getReceiveMessageRequest()).getMessages();
SOPL(newResults);
I am having the following problems with my code.
- When I am printing results list, I am expecting 2 messages, but only one message is being printed and the list size is also printed as 1.
- After deleteMessagesInQueue function call, I expect all the messages to be deleted in the SQS and the newResults list size should be 0, but one message is being printed and queue size is printed as 1. I can do purgeQueue instead of delete, but I want to understand what I am doing wrong here?