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);