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.

gefragt vor 2 Jahren579 Aufrufe
1 Antwort
2
Akzeptierte Antwort

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
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen