Not using Long Polling?
MarkSonghurst opened this issue · 2 comments
Hello
I enjoyed reading your blog post and it lead me to this repository. Thanks for providing a very interesting solution.
I do have one question though.
In my research of the AWS SDK for SQS, it seems that to enable Long Polling, the ReceiveMessage function needs to be called with the ReceiveMessageInput.WaitTimeSeconds parameter set to a non-nil and non-zero integer.
https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sqs-example-enable-long-polling.html (scroll down to the "Enable long polling when a message is received" section)
https://docs.aws.amazon.com/sdk-for-go/api/service/sqs/#ReceiveMessageInput
As you are not setting ReceiveMessageInput.WaitTimeSeconds I think you are actually using short polling in your package
https://github.com/qhenkart/gosqs/blob/master/consumer.go line 151
output, err := c.sqs.ReceiveMessage(&sqs.ReceiveMessageInput{QueueUrl: &c.QueueURL, MaxNumberOfMessages: &maxMessages, MessageAttributeNames: []*string{&all}})
Maybe this was by design for performance?
Thanks again, Mark.
@MarkSonghurst Thank you for your message and creating the first issue of this repo. I am pleased you took the time to take a look at the code and make an issue here.
There are two ways the documentation explains that long polling can be enabled
- Modifying the Queue parameter (either on creation or after creation as the documentation explains)
- As a one time parameter for a specific message (I'm fairly certain this option did not exist when I designed this library)
Docs:
You can do this(enabling long polling) by setting the ReceiveMessageWaitTimeSeconds parameter of a queue or by setting the WaitTimeSeconds parameter on a message when it is received.
In the Readme file in this repo. I go over the provisioning of the Queues, including setting up the WaitTimeSeconds to enable Long Polling as a default functionality of the queue.
While the SQS/SNS API allows for provisioning, it's a bit outside of the realm of this package as it's more of a driver to interface with existing SQS queues. In the project I developed this for, provisioning was handled separately via terraform, and was a one time set up for an environment.
To be honest, I'm not sure why AWS decided to make short polling the default instead of long polling. Their docs heavily suggest that everyone should use long polling. It's worth noting that every polling request to an SQS queue has a (very very small) financial cost, so short polling would also be 20 times more expensive than long polling
HI.
Thanks for the explanation.