tjmehta / coworkers

A RabbitMQ Microservice Framework in Node.js
MIT License
610 stars 36 forks source link

Clustering / Process management ( DISABLE ) #51

Closed protzi closed 6 years ago

protzi commented 7 years ago

Hello, i try to use coworkers and rabbitmq-schema; if for some reason i want to disable workers, and left only ONE, but i have two or more queue, how to properly use 1 worker ( = 1 process ) ?

process.env.COWORKERS_CLUSTER = false;
process.env.COWORKERS_QUEUE = 'queue1'; <= should i define here 1 queue or more ?
//process.env.COWORKERS_QUEUE_WORKER_NUM = 1;
tjmehta commented 7 years ago

Hey Protzi,

I believe what you have so far is correct.

To manage your queue processes manually specify env for each of your process independently.

For your queue1 process 1 specify:

process.env.COWORKERS_CLUSTER = false;
process.env.COWORKERS_QUEUE = 'queue1';
COWORKERS_QUEUE_WORKER_NUM=1;

For your queue2 process 1 specify:

process.env.COWORKERS_CLUSTER = false;
process.env.COWORKERS_QUEUE = 'queue2';
COWORKERS_QUEUE_WORKER_NUM=1;

If you have multiple processes per queue: For your queue1 process 2 specify:

process.env.COWORKERS_CLUSTER = false;
process.env.COWORKERS_QUEUE = 'queue1';
COWORKERS_QUEUE_WORKER_NUM=2;

And so on.

This allows your queues' to share the same code base, while decoupling your queues' processes.

Does that make sense? If not, tell me more about the problem you are encountering.

protzi commented 7 years ago

ok it seems make sense, but if i have multiple queues for 1 process ? Or its a bad idea ?:)

process.env.COWORKERS_CLUSTER = ? 
process.env.COWORKERS_QUEUE = ?
COWORKERS_QUEUE_WORKER_NUM= ?
app.queue('firstQueue'...

app.queue('secondQueue'...
tjmehta commented 7 years ago

There is no way to have multiple queues in 1 process using coworkers. When you use clustering, coworkers creates a child process per queue. When disabling clustering you are specifying a queue per process manually using environment variables.