Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon SQS "Long Polling" configuration. Server vs Client

A long time ago, Amazon introduced the long polling feature. And with that, it is possible to configure on the Queue the "Receive Message Wait Time" parameter. According to the documentation, a valid value falls in the range 0 - 20 seconds.

enter image description here

In the client, we can also configure this parameter on each MessageReceiveRequest. I'm using the AWS SDK for .NET.

var receiveRequest = new ReceiveMessageRequest 
{ 
    QueueUrl = "https://queue-url-goes-here.com", 
    MaxNumberOfMessages = 10, 
    VisibilityTimeout = 30, 
    WaitTimeSeconds = 20 // This should tell if we want long polling or not
 };

Questions:

a) What is the relationship between the Receive Message Wait Time configured in the Queue VS the WaitTimeSeconds attribute set in the Message Receive Request? Will they work independently? Or the value set in the client overrides the value set in the Queue (for that single request).

b) Under certain conditions, can the C# client time out? I am thinking about setting both values to the max (20 seconds) but I'm afraid that might cause the C# long polling operation to Time Out.

c) What is the best-practice. WaitTimeSeconds > Receive Message Wait Time?

like image 559
Adrian Salazar Avatar asked Nov 05 '14 23:11

Adrian Salazar


1 Answers

a) As noted in pastk's answer, the WaitTimeSeconds on the message will override the Receive Message Wait Time configured in the queue. See the long polling documentation for details.

b) The AWS SDK for .NET uses System.Net.HttpWebRequest under the hood - its default timeout is 100 seconds. If you're using the defaults, setting the WaitTimeSeconds to 20 seconds will not cause the operation to time out.

c) There is no best practice prescribed by Amazon on this point. Do whatever you think is best for your scenario.

like image 96
Adrian Hofman Avatar answered Oct 16 '22 07:10

Adrian Hofman