sqs-consumer icon indicating copy to clipboard operation
sqs-consumer copied to clipboard

Best practices for production

Open uberism opened this issue 8 years ago • 3 comments

Currently, I have a node app with express running inside a docker container. My traffic is quite low right now, so I was thinking of consuming my low volume sqs messages on the same server.

I was wondering what would be the best method of running this long polling receive function. On my local machine, I am running it as a node script. Eg. Start our express app and run the file that contains the code to consume and poll the queue.

uberism avatar Aug 23 '18 19:08 uberism

We run a server and consumer on the same process quite frequently. We haven't had any problems doing something like below:

const express = require('express');
const app = express();

const handleMessage = require('./handleMessage');

const consumer = new Consumer({
  handleMessage,
  queueUrl: 'url',
  region: 'region'
});

consumer.on('error', () => {
  // handle
});

consumer.start();
app.listen(8080);

cejast avatar Aug 24 '18 07:08 cejast

Thanks for the response @cejast I was looking to use node fork to run consumer.start(); https://stackoverflow.com/questions/17861362/node-js-child-process-difference-between-spawn-fork provided a good explanation on its uses. I want to make sure that there will be no stability issues on production since its extremely important that our app processes the jobs.

uberism avatar Aug 24 '18 16:08 uberism

Sure. We use cluster which forks processes in tandem with the above approach. We've been running things like this in production for a couple years now and haven't had issues with it.

cejast avatar Aug 28 '18 09:08 cejast