Movatterモバイル変換


[0]ホーム

URL:


CtrlK
On this page

NestJs

There is a compatible module to be used inNestJs based on@nestjs/bullmq.

yarnadd@taskforcesh/nestjs-bullmq-pro

BullMQ-Pro needs a token, as explained in theinstall section.

Once the installation process is complete, we can import theBullModule into the rootAppModule.

import { Module }from'@nestjs/common';import { BullModule }from'@taskforcesh/nestjs-bullmq-pro';@Module({  imports: [BullModule.forRoot({      connection: {        host:'localhost',        port:6379,      },    }),  ],})exportclassAppModule {}

To register a queue, import theBullModule.registerQueue() dynamic module, as follows:

BullModule.registerQueue({  name:'queueName',});

To register a flow producer, import theBullModule.registerFlowProducer() dynamic module, as follows:

BullModule.registerFlowProducer({  name: 'flowProducerName',});

Processor

To register a processor, you may need to useProcessor decorator:

import {  Processor,  WorkerHost,  OnWorkerEvent,} from '@taskforcesh/nestjs-bullmq-pro';import { JobPro } from 'taskforcesh/bullmq-pro';@Processor('queueName')class TestProcessor extends WorkerHost {  async process(job: JobPro<any, any, string>): Promise<any> {    // do some stuff  }  @OnWorkerEvent('completed')  onCompleted() {    // do some stuff  }}

And then register it as a provider:

@Module({  imports: [    BullModule.registerQueue({      name: 'queueName',      connection: {        host: '0.0.0.0',        port: 6380,      },    }),    BullModule.registerFlowProducer({      name: 'flowProducerName',      connection: {        host: '0.0.0.0',        port: 6380,      },    }),  ],  providers: [TestProcessor],})export class AppModule {}

Example

A working example is availablehere.

Read more:

Last updated

Was this helpful?


[8]ページ先頭

©2009-2025 Movatter.jp