How to turn on Long Polling on an AWS SQS Queue

The following code snippet will allow you to configure an AWS SQS queue for long polling using the ReceiveMessageWaitTimeSeconds attribute. For more information about Amazon long polling, see here:

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html

// 5. Set Queue attributes
// The API Version 2012-11-05 of Amazon SQS provides support for long polling. (.net sdk v2)
// In the AWS console, you can verify in "Receive Message Wait Time" value of the queue
SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest();
List<Amazon.SQS.Model.Attribute> attributes = new List<Amazon.SQS.Model.Attribute>();
Amazon.SQS.Model.Attribute attribute = new Amazon.SQS.Model.Attribute();
attribute.Name = "ReceiveMessageWaitTimeSeconds";
attribute.Value = "20"; // 0 to 20 Seconds, default is 0
attributes.Add(attribute);
setQueueAttributesRequest.QueueUrl = queueUrl;
setQueueAttributesRequest.Attribute = attributes;
_sqs.SetQueueAttributes(setQueueAttributesRequest);
Advertisements

3 thoughts on “How to turn on Long Polling on an AWS SQS Queue

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s