Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added docs for bullmq's manual registration option #3190

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions content/techniques/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The `forRoot()` method is used to register a `bullmq` package configuration obje
- `prefix: string` - Prefix for all queue keys. Optional.
- `defaultJobOptions: JobOpts` - Options to control the default settings for new jobs. See [JobOpts](https://github.com/OptimalBits/bull/blob/master/REFERENCE.md#queueadd) for more information. Optional.
- `settings: AdvancedSettings` - Advanced Queue configuration settings. These should usually not be changed. See [AdvancedSettings](https://github.com/OptimalBits/bull/blob/master/REFERENCE.md#queue) for more information. Optional.
- `extraOptions` - Extra options for module init. See [Manual Registration](https://docs.nestjs.com/techniques/queues#manual-registration)

All the options are optional, providing detailed control over queue behavior. These are passed directly to the BullMQ `Queue` constructor. Read more about these options and other options [here](https://api.docs.bullmq.io/interfaces/v4.QueueOptions.html).

Expand Down Expand Up @@ -465,6 +466,37 @@ BullModule.registerQueueAsync({
});
```

#### Manual registration

By default, `BullModule` is automatically registring BullMQ components (queues processors and event listeners services) in an `onModuleInit` life-cycle function. In some use cases this behavior isn't ideal, so to prevent this you should enable `manualRegistration` in `BullModule` as such:

```typescript
BullModule.forRoot({
extraOptions: {
manualRegistration: true,
},});
```

In order to regiter those components you should inject `BullRegistrar` and call the `register` function (ideally in an `OnModuleInit` or `OnApplicationBoostrap`).

```typescript
import { Injectable, OnModuleInit } from '@nestjs/common';
import { BullRegistrar } from '@nestjs/bullmq';

@Injectable()
export class AudioService implements OnModuleInit {
constructor(private bullRegistrar: BullRegistrar) {}

onModuleInit() {
if (something) {
this.bullRegistrar.register();
}
}
}
```

Unless you're calling the `BullRegistrar#register` function no BullMQ component will work (e.g no job will be processed).

#### Bull installation

> warning **Note** If you decided to use BullMQ, skip this section and the following chapters.
Expand Down