Integrates BullMQ with Nest
npm install nestjs-bullmq bullmq
You can also use the interactive CLI
npx nestjs-modules
import { Module } from '@nestjs/common';
import { BullMQModule } from 'nestjs-bullmq';
import { AppController } from './app.controller';
@Module({
imports: [
BullMQModule.forRoot({
name: 'QueueName',
config: {
// url: 'redis://:password@localhost:6379',
connection: { host: 'localhost', port: 6379 },
},
}),
],
controllers: [AppController],
})
export class AppModule {}
import { Module } from '@nestjs/common';
import { BullMQModule } from 'nestjs-bullmq';
import { AppController } from './app.controller';
@Module({
imports: [
BullMQModule.forRootAsync({
name: 'QueueName',
useFactory: () => ({
config: {
// url: 'redis://:password@localhost:6379',
connection: { host: 'localhost', port: 6379 },
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
import { Controller, Get, } from '@nestjs/common';
import { InjectBullMQ, BullMQ } from 'nestjs-bullmq';
@Controller()
export class AppController {
constructor(
@InjectBullMQ('QueueName') private readonly bullMQ: BullMQ,
) {}
@Get()
async getHello() {
this.bullMQ.process(async job => {
console.log('process', job);
})
this.bullMQ.queue.add('myJobName', { foo: 'bar' });
// this.bullMQ.queueEvents.on();
// this.bullMQ.queueScheduler.on();
}
}
MIT