High-performance Redis Streams queue integration for NestJS based on power-queues.
npm install nestjs-power-queues
`` bash`
npm install nestjs-power-queues`
ORbash`
yarn add nestjs-power-queues
env
REDIS_QUEUES_HOST=127.0.0.1
REDIS_QUEUES_PORT=6379
REDIS_QUEUES_PASSWORD=
REDIS_QUEUES_DATABASE=0
`For information on creating connections to Redis, see nestjs-power-redis
$3
`ts
import { QueueModule } from 'nestjs-power-queues';@Module({
imports: [
QueueModule.forRoot([ 'queues' ]),
],
})
export class AppModule {}
`$3
`ts
import { Injectable } from '@nestjs/common';
import {
InjectQueue,
QueueService,
} from 'nestjs-power-queues';@Injectable()
export class MyService {
constructor(
@InjectQueue('queues') private readonly queueService: QueueService,
) {}
async test() {
await this.queueService.addTasks('example:jobs', [
{ payload },
]);
}
}
`$3
`ts
import { Injectable } from '@nestjs/common';
import {
InjectRedis,
RedisService,
} from 'nestjs-power-redis';
import { QueueService } from 'nestjs-power-queues';@Injectable()
export class MyService extends QueueService {
public readonly stream: string =
example:jobs;
public readonly workerBatchTasksCount: number = 8192;
public readonly runOnInit: boolean = true;
public readonly executeBatchAtOnce: boolean = true; constructor(
@InjectRedis('queues') public readonly redisService: RedisService,
) {}
async onExecute(id, payload) {
// business-logic
}
}
`The
runOnInit` parameter determines whether queue processing should start immediately after the application starts.