title: Restart a cluster worker in nodejs not listening for connections
body: <p>I have a use case where I need to dedicate one worker to listen for incoming messages from an AWS sqs queue and process them, the rest of the workers are listening on the desired port for connection. Following is the code</p>
  
  <pre><code>var cluster = require('cluster');
  
  if (cluster.isMaster) {
    /** Master process */
  
    /**
     * spawn a worker for each available cpu
     * HACK: Downsizing worker count will not restore tasks that were handled by those extra workers
     */
    var cpuCount = require('os').cpus().length;
    for (var i = 0; i &lt; cpuCount; i += 1) {
      cluster.fork();
    }
    /** re-spawn worker if dead */
    cluster.on('exit', function(worker) {
      console.log('worker-' + worker.id + ' died');
      cluster.fork();
    });
  
  } else if (cluster.worker.id == 1) {
    // Check for incoming messages from an AWS SQS queue
  } else {
    //Listen on the port for connections 
  }
  </code></pre>
  
  <p>If the worker listening for connection on the port dies, it is revived. But, I cannot figure out the solution of how to revive the worker which is listening for incoming messages from the SQS queue if it dies due to some error.</p>