Best practices for production
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.
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);
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.
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.