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년 전578회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠