Run callback when SQS gets message?

0

I'm making a NodeJS app with the aws-sdk package and SQS. My app needs to run some docker-related commands programmatically on my servers (it's a code running app), and I'm using SQS to slow the requests down. Right now, I am polling SQS at an interval of ~1 second for requests, but I think that this is a bad practice since it is steadily draining my limit.

Is there any API I can use to call a callback when SQS gets a message? Something like:

sqs.setCallback((err, data) => {
   //my code here
}, "onmessagerecieve")

If SQS doesn't have this API, are there any alternatives? Messages should be received in the queue in 1-30 seconds.

質問済み 2年前548ビュー
1回答
2
承認された回答

There is no callback method for SQS as its a managed external queue.

You should take a look at enabling long polling on your queue and then that would allow you to run your poller way less frequently than every second. You can find more information here: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html and in the specific SDK documentation. With this you could poll ~every 15-20 seconds or so and wait for messages to arrive.

Thanks,

  • munns
munns
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ