How To Configure Delay Queue In SQS

How To Configure Delay Queue In SQS

How to configure delay queue in SQS

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to enable long polling in SQS.

https://cloudaffaire.com/how-to-enable-long-polling-in-sqs-queue/

In this blog post, we will discuss how to configure delay queue in SQS.

How to configure delay queue in SQS:

AWS SQS provides delivery delay option to postpone the delivery of new messages to a queue. If delivery delay is defined for a queue, any new message will not be visible to the consumer for the duration of delay. The default (minimum) delay for a queue is 0 seconds. The maximum is 15 minutes.

Delay queues are similar to visibility timeouts because both features make messages unavailable to consumers for a specific period of time. The difference between the two is that, for delay queues, a message is hidden when it is first added to queue, whereas for visibility timeouts a message is hidden only after it is consumed from the queue. To set delay seconds on individual messages, rather than on an entire queue, use message timers to allow Amazon SQS to use the message timer’s DelaySeconds value instead of the delay queue’s DelaySeconds value.

How To Configure Delay Queue In SQS

Note: For standard queues, the per-queue delay setting is not retroactive; changing the setting doesn’t affect the delay of messages already in the queue. But for FIFO queues, the per-queue delay setting is retroactive; changing the setting affects the delay of messages already in the queue.

Next, we are going to configure delay queue in SQS through AWS CLI

Prerequisite for this demo:

  • AWS SQS FIFO queue.
  • AWS CLI configured with required access.

Step 1: Configure AWS CLI.

Step 2: Query the list of queues available and copy the queue URL.

How To Configure Delay Queue In SQS

Step 3: Get the current queue attributes.

How To Configure Delay Queue In SQS

Note: Currently no delay queue has been configured (DelaySeconds = 0).

Step 4: Enable delay queue of 10 minutes.

Step 5: Send a message to the queue.

Step 6: Try to consume the message within 10 mins from executing the above command.

How To Configure Delay Queue In SQS

Observation: We have enabled delay of 10 minutes and since this is a FIFO queue, the delay will be applied to all messages including the existing ones. If we send a message and try to consume it within 10 minutes, we will receive an empty response even in case of long polling.

Hope you have enjoyed this article. In the next blog post, we will discuss the dead letter queue in SQS.

To get more details on AWS SQS, please refer below AWS documentation

https://docs.aws.amazon.com/sqs/index.html

 

Leave a Reply

Close Menu