Dipak Panchal
Dipak Panchal

Reputation: 6026

Jobs pushing to queue, but not processing

I am using AWS SQS. I am getting 2 issues.

  1. Sometime, messages are present in the queue but I am not able to read that. When I fetch, I am getting blank array, same like not any messages found in queue.

  2. When I am deleting a message from queue then it gives me like

sqs.delete_message({queue_url: queue_url, receipt_handle: receipt_handle})

=> Aws::EmptyStructure

When I check in SQS (In AWS), message still present even I refresh page more then 10 times.

Can you help me why this happens ?

Upvotes: 1

Views: 128

Answers (1)

Soubhik Mondal
Soubhik Mondal

Reputation: 2666

1. You may need to implement Long Polling.

SQS is a distributed system. By default, when you read from a queue, AWS returns you the response only from a small subset of its servers. That's why you receive empty array some times. This is known as Short Polling.

When you implement Long Polling, AWS waits until it gets the response from all it's servers.

When you're calling ReceiveMessage API, set the parameter WaitTimeSeconds > 0.

2. Visibility Timeout may be too short.

The Visibility Timeout controls how long a message currently being read by one poller is invisible to other pollers. If the visibility timeout is too short, then other pollers may start reading the message before your first poller has processed and deleted it.

Since SQS supports multiple pollers reading the same message. From the docs -

The ReceiptHandle is associated with a specific instance of receiving a message. If you receive a message more than once, the ReceiptHandle is different each time you receive a message. When you use the DeleteMessage action, you must provide the most recently received ReceiptHandle for the message (otherwise, the request succeeds, but the message might not be deleted).

Upvotes: 2

Related Questions