Nest-Bullmq – NestJS wrapper for BullMQ
This dynamic module was generated with Nest Dynamic Package Generator Schematics. You can read more about using the generator here.
Installation
To install this generated project:
npm install nest-bullmq --save
(or yarn equivalent)
Test
You can test this module against your Redis server (set in the .env file)
cd ./node_modules/nest-bullmq
npm run start:dev
Then connect to http://localhost:3000 and you should see the status of your BullMQ instance.
Usage
@Module({
imports: [
ConfigModule.forRoot(),
NestBullmqModule.registerAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => {
return {
connection: ((url) => {
if (!url) return {};
url = new URL(url);
return {
host: url.hostname,
port: parseInt(url.port),
username: url.username,
password: url.password,
};
})(configService.get('REDIS_URL')),
};
},
inject: [ConfigService],
}),
],
})
Look at src/nest-bullmq-client
for more details.
This wrapper is using bullmq module, so take a look how to use it.
@Controller()
export class NestBullmqClientController {
constructor(private readonly nestBullmqService: NestBullmqService) {}
@Get()
async index() {
// create instances with options included:
const flowProducer = this.nestBullmqService.create('FlowProducer')();
// or create directly
const Bullmq = this.nestBullmqService.getBullmq();
const options = this.nestBullmqService.getOptions();
return new Bullmq.FlowProducer(options);
}
}
Good luck!