1

I have to utilize one worker for more than one Queue. Is this possible in bullmq? As I went through the documentation I found option to provide only one queue name for worker. Is there any way using that I can allocate single worker to process multiple queues?

Thanks...

Lalit Kolate
  • 31
  • 1
  • 4

1 Answers1

1

You can subcribe the worker to one queue
but when publishing a job give it a specific name to distinguish between different handlers.

For instance here's how you can publish jobs with different name to the same worker:

const queue = new Queue('math');
await queue.add('factorial', { number: 42 });
await queue.add('check_prime', { number: 31 });

And here's how you can subcribe and process them:

const worker = new Worker('math', async (job) => {
  if (job.name === 'factorial') {
    // Do something
  } else if (job.name === 'check_prime') {
    // Do something else
  }
});
Pavel Bely
  • 2,245
  • 1
  • 16
  • 24
  • I have a case where job name would be the same for different queue. For example there are 2 types of job (import/export) but the queue will be based on the organisation or its CRM. – Manish Jul 04 '23 at 15:58