before I explain the problem in details, I tell you my current approach.
I have a js script that run setInterval().
and each interval, I will call SQS to get the message from queue. If there is a message, then I process it.
so, it will run infinitely until I kill the process.
I have also built a node server before (using the example in the nodejs.org )
So, what I'm wondering is,.. instead of having the setInterval to run periodically. Is there a way that if There is a new message in the SQS, then it will fire an event and process the message?
No. You must request a message from SQS.
Take a look at SNS if you really need push notifications. SNS works well if you want give your server a hint to poll SQS after you add a message to the queue.
This questions is over 2 years old.. but there is a much better way than changing your polling interval. Instead set the Receive Message Wait Time of your queue to the maximum of 20 seconds. Then you can do continuous polling but will only make 3 requests per minute while the queue is empty. When there is data in the queue the response will be immediate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With