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.

preguntada hace 2 años579 visualizaciones
1 Respuesta
2
Respuesta aceptada

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
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas