BullModule
Integrates BullMQ for Redis-backed background job queues.
Syntax
BullModule.forRoot(options) | BullModule.registerQueue({ name }) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
options | object | No | connection settings for the Redis instance. |
Returns
DynamicModule — A module wiring queues and processors.
Examples
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
@Module({
imports: [
BullModule.forRoot({ connection: { host: 'localhost', port: 6379 } }),
BullModule.registerQueue({ name: 'emails' }),
],
})
export class QueueModule {}
import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Job } from 'bullmq';
@Processor('emails')
export class EmailProcessor extends WorkerHost {
async process(job: Job<{ to: string }>) {
await sendEmail(job.data.to);
}
}
Notes
Install @nestjs/bullmq and bullmq with a running Redis. Inject the queue
with @InjectQueue('emails') to add jobs, and define a @Processor class
extending WorkerHost to consume them.