Reputation: 781
I have a use case where I have to delay the message visibility to the consumers for about 15 minutes but if there's a change of event within that 15 minute duration; I should cancel the message so that the state ends there.
I see that Amazon SQS message timers are applicable for this scenario but I am not able to get that to satisfy the second part of the requirement.
Would this be programatically possible?
In the documentation https://docs.amazonaws.cn/en_us/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html it is mentioned that an Amazon SQS message has three basic states:
I understand that the message can be deleted after it is consumed but how do I delete or expire it before even it is visible to the consumers?
Are there any other AWS service I can use? Looking at step functions but not exactly fitting this simple use case mentioned above.
Any pointers would be greatly helpful.
Please bear with me / AWS noob. Thanks.
Upvotes: 0
Views: 1420
Reputation: 781
Are there any other AWS service I can use? Looking at step functions but not exactly fitting this simple use case mentioned above.
Answering my own question as there are other AWS services that can be employed in such a use-case:
I am now using AWS Step Functions to delay the message sent to an SNS.
I have a Lambda function that is subscribed to the SNS that gets triggered after the set time.
I followed through the YouTube Video AWS Step Functions with Lambda Tutorial | Step by Step Guide for configuring Step Functions with Lambda.
I hope it will be useful to someone with a similar use case instead of trying to work with the limitations of SQS.
Upvotes: 1
Reputation: 2096
Deleting a message from ana SQS Queue without receiving it is not possible.
From AWS Docs -
To delete a message, you must send a separate request which acknowledges that you've successfully received and processed the message. Note that you must receive a message before you can delete it.
To solve your problem, I can think of this approach -
Current Setup that you have -
1. Send message to SQS Q1
2. Delay of 15 minutes.
3. Message received by all subscribers of Q1 (say S1, S2, S3).
Modified setup
1. Send Message to SQS Q1.
2. Delay of 15 minutes.
3. Message received by a new Subscriber (say Sx) of SQS Q1.
4. Subscriber checks the event details and decides whether or not to cancel the event.
5. If event is to be cancelled, delete it.
6. Else, send it to the DLQ of Q1 (Say Q2). More info on DLQs here - https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html.
7. Q2 can now have the previous set of Subscribers (S1, S2, S3)
Upvotes: 3