The most efficient way to poll Amazon SQS queues with Node

My question is short, but I think it is interesting:

I have a queue from Amazon's SARS service and I check the queue every second. When the message is processed and after processing, return to the poll queue.

Is there a better way to do this ?, some kind of trigger? or which approach would be the best, in your opinion, and why.

Thanks!

+5
source share
3 answers

A useful and easy to use library for consuming messages from SQS is sqs-consumer

const Consumer = require('sqs-consumer'); const app = Consumer.create({ queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name', handleMessage: (message, done) => { console.log('Processing message: ', message); done(); } }); app.on('error', (err) => { console.log(err.message); }); app.start(); 

This is well documented if you need more information. Documents can be found at: https://github.com/bbc/sqs-consumer

+5
source

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

you can configure the SQS queues to "timeout for receiving a message" and do a long poll.

so that you can tell him 10 seconds, and the call will return only if you have a message or after 10 seconds. You can continuously poll the queue in this scenario.

+3
source

As Mircea mentioned, a lengthy survey is one option.

When you request a "trigger", I find that you are looking for something else besides constantly polling SQS yourself. If so, I suggest you take a look at AWS Lambda. It allows you to host code in the cloud that automatically runs on your configured events, such as an SNS event, a file pressed on S3, etc.

http://aws.amazon.com/lambda/

+1
source

All Articles