Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/svtslv/nestjs-bullmq

BullMQ module for NestJS
https://github.com/svtslv/nestjs-bullmq

bull bullmq nest nestjs queue redis

Last synced: 7 days ago
JSON representation

BullMQ module for NestJS

Awesome Lists containing this project

README

        

# NestJS BullMQ

NPM Version
Package License

## Table of Contents

- [Description](#description)
- [Installation](#installation)
- [Examples](#examples)
- [License](#license)

## Description
Integrates BullMQ with Nest

## Installation

```bash
npm install nestjs-bullmq bullmq
```

You can also use the interactive CLI

```sh
npx nestjs-modules
```

## Examples

### BullMQModule.forRoot(options, connection?)

```ts
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 {}
```

### BullMQModule.forRootAsync(options, connection?)

```ts
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 {}
```

### InjectBullMQ(queueName?, connection?)

```ts
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();
}
}
```

## License

MIT