Skip to content
Get started
Get started
QueueGroup: Namespace Related Queues
View Markdown
guide · queue-group

Many queues, one namespace.

QueueGroup prefixes a set of queues with a shared name, so “invoices” inside the “billing” group becomes “billing:invoices”. Handy for multi-tenant apps and keeping domains apart.

A QueueGroup is a thin organizer: it creates normal Queue and Worker instances whose names carry the group prefix, and it can pause, resume, or clear all of them at once.

import { QueueGroup } from 'bunqueue/client';
const billing = new QueueGroup('billing');
// Queues are automatically prefixed
const invoices = billing.getQueue('invoices', { embedded: true }); // "billing:invoices"
const payments = billing.getQueue('payments', { embedded: true }); // "billing:payments"
await invoices.add('create', { amount: 100 });
await payments.add('process', { orderId: '123' });
// Workers use the same prefixed names
const invoiceWorker = billing.getWorker('invoices', async (job) => {
console.log('Processing invoice:', job.data);
return { processed: true };
}, { embedded: true });

Both TypeScript packages expose QueueGroup; getQueue and getWorker accept the same options as Queue and Worker. Node.js and Deno use TCP. Use the Async group methods to act on registered remote queues. The other SDK examples create normal queues and workers with the same prefixed names.

billing.listQueues(); // ['invoices', 'payments'] (names without prefix)
billing.pauseAll(); // pause every queue in the group
billing.resumeAll(); // resume them
billing.drainAll(); // remove all waiting jobs
billing.obliterateAll(); // remove ALL data from every queue
// Awaitable forms are authoritative in embedded and TCP modes
await billing.pauseAllAsync();
await billing.resumeAllAsync();
const removed = await billing.drainAllAsync();
await billing.obliterateAllAsync();
const tenantA = new QueueGroup('tenant-a');
const tenantB = new QueueGroup('tenant-b');
const tasksA = tenantA.getQueue('tasks', { embedded: true }); // "tenant-a:tasks"
const tasksB = tenantB.getQueue('tasks', { embedded: true }); // "tenant-b:tasks"
const env = process.env.NODE_ENV || 'development';
const group = new QueueGroup(`${env}-tasks`);
const queue = group.getQueue('jobs', { embedded: true });
// "development-tasks:jobs" or "production-tasks:jobs"
MethodDescription
getQueue(name, opts?)Get a queue within the group (embedded or TCP)
getWorker(name, processor, opts?)Create a worker for a queue in the group (embedded or TCP)
listQueues()List queue names in the group, without prefix (embedded only)
pauseAll()Pause all queues in the group (embedded only)
resumeAll()Resume all queues in the group (embedded only)
drainAll()Remove waiting jobs from all queues (embedded only)
obliterateAll()Remove all data from all queues (embedded only)
listQueuesAsync()List tracked group queues in either runtime
pauseAllAsync() / resumeAllAsync()Await group control in either runtime
drainAllAsync()Drain all tracked queues and return the aggregate count
obliterateAllAsync()Await removal of all tracked queue data