Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the nodejs server listen to AWS SQS?

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?

like image 223
murvinlai Avatar asked Feb 02 '11 00:02

murvinlai


2 Answers

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.

like image 54
Uriah Carpenter Avatar answered Sep 20 '22 17:09

Uriah Carpenter


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.

like image 39
bvs Avatar answered Sep 20 '22 17:09

bvs