Skip to content

Commit 68b0560

Browse files
Merge branch 'feature/add-manual-registration-docs' of https://github.com/idbenami/docs.nestjs.com into idbenami-feature/add-manual-registration-docs
2 parents 4ba8474 + 08f527a commit 68b0560

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

content/techniques/queues.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The `forRoot()` method is used to register a `bullmq` package configuration obje
4646
- `prefix: string` - Prefix for all queue keys. Optional.
4747
- `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.
4848
- `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.
49+
- `extraOptions` - Extra options for module init. See [Manual Registration](https://docs.nestjs.com/techniques/queues#manual-registration)
4950

5051
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).
5152

@@ -465,6 +466,37 @@ BullModule.registerQueueAsync({
465466
});
466467
```
467468

469+
#### Manual registration
470+
471+
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:
472+
473+
```typescript
474+
BullModule.forRoot({
475+
extraOptions: {
476+
manualRegistration: true,
477+
},});
478+
```
479+
480+
In order to regiter those components you should inject `BullRegistrar` and call the `register` function (ideally in an `OnModuleInit` or `OnApplicationBoostrap`).
481+
482+
```typescript
483+
import { Injectable, OnModuleInit } from '@nestjs/common';
484+
import { BullRegistrar } from '@nestjs/bullmq';
485+
486+
@Injectable()
487+
export class AudioService implements OnModuleInit {
488+
constructor(private bullRegistrar: BullRegistrar) {}
489+
490+
onModuleInit() {
491+
if (something) {
492+
this.bullRegistrar.register();
493+
}
494+
}
495+
}
496+
```
497+
498+
Unless you're calling the `BullRegistrar#register` function no BullMQ component will work (e.g no job will be processed).
499+
468500
#### Bull installation
469501

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

0 commit comments

Comments
 (0)