Reputation: 341
So I am new to Amazon SQS, I watched a few tutorials and it was mentioned that messages in the queue are not deleted and they remain in the queue (retention period is set by us), there is a visibility timeout and if one consumer is consuming that message the other consumer will have to wait till the visibility timeout get's over. After the visibility timeout is over the other consumer can access the message.
Now in another tutorial, a person consumed the message using SQSListner, it was a spring boot app, and after the consumption, the message was automatically deleted from the queue, how did it happen?
@SqsListener("javatechie-queue")
public void loadMessageFromSQS(String message) {
logger.info("message from SQS Queue {}",message);
}
Upvotes: 1
Views: 2022
Reputation: 10704
it was a spring boot app, and after the consumption, the message was automatically deleted from the queue. How did it happen?
The Amazon SQS Java V2 API also provides a method that lets you purge messages from a queue using Java logic like this:
public void purgeMyQueue() {
SqsClient sqsClient = getClient();
GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder()
.queueName(QUEUE_NAME)
.build();
PurgeQueueRequest queueRequest = PurgeQueueRequest.builder()
.queueUrl(sqsClient.getQueueUrl(getQueueRequest).queueUrl())
.build();
sqsClient.purgeQueue(queueRequest);
}
So you can purge a queue in your app using this logic. If you want to learn how to use the Amazon SQS Java API in a Spring Boot app, see this AWS tutorial:
Creating an example messaging application using the AWS SDK for Java
Upvotes: 2