nestjs-dynamic-queue
v0.1.0
Published
The nestjs-dynamic-queue package is a NestJS module that allows you to create queues at runtime and send messages to them. It provides a wrapper around the bull package, which is a powerful Redis-based queue library. With nestjs-dynamic-queue, you can eas
Downloads
67
Readme
Introduction
The nestjs-dynamic-queue package is a NestJS module that allows you to create queues at runtime and send messages to them. It provides a wrapper around the bull package, which is a powerful Redis-based queue library. With nestjs-dynamic-queue, you can easily integrate queue functionality into your NestJS application and leverage the features provided by bull, such as job scheduling, retries, and prioritization.
Installation
yarn add nestjs-dynamic-queue
or
npm i nestjs-dynamic-queue
Usage
Importing module Async
import { DynamicQueueModule, DynamicQueueConnectOptions } from 'nestjs-dynamic-queue';
@Module({
imports: [
DynamicQueueModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService): Promise<DynamicQueueConnectOptions> => ({
queueNamePrefix: 'prefix',
redis: {
host: configService.get('REDIS_HOST'),
port: configService.get('REDIS_PORT'),
password: configService.get('REDIS_PASSWORD'),
},
defaultJobOptions: {
attempts: 4,
},
initialQueueNames: ['someInitialQueue'],
})
})
],
providers: [],
exports: [],
})
export class AppModule {}
Add queue and create task
import { DynamicQueueService } from 'nestjs-dynamic-queue';
@Injectable()
export class YourService {
constructor(private dynamicQueueService: DynamicQueueService) {}
async method() {
await this.dynamicQueueService.addTask('queue', 'type task', payload);
return;
}
}
Create processor and processes
import { Processor, Process } from from 'nestjs-dynamic-queue';
@Processor()
export class WebhookProcessor {
constructor(private readonly yourService: YourService) {}
@Process({ name: 'type task', concurrency: 1 })
async clean(job: Job<IAddTaskPayload>) {
await this.yourService.processTask(job.data);
}
}
Contributing
Contributions welcome! See Contributing.
Author
Yaroslav Tolstoy Site
License
Licensed under the MIT License - see the LICENSE file for details.