Skip to content

Commit 98ec8f0

Browse files
Merge branch 'idbenami-feature/add-manual-registration-docs'
2 parents 4ba8474 + b81d297 commit 98ec8f0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

content/techniques/queues.md

Lines changed: 33 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,38 @@ BullModule.registerQueueAsync({
465466
});
466467
```
467468

469+
#### Manual registration
470+
471+
By default, `BullModule` automatically registers BullMQ components (queues, processors, and event listener services) in the `onModuleInit` lifecycle function. However, in some cases, this behavior may not be ideal. To prevent automatic registration, enable `manualRegistration` in `BullModule` like this:
472+
473+
```typescript
474+
BullModule.forRoot({
475+
extraOptions: {
476+
manualRegistration: true,
477+
},
478+
});
479+
```
480+
481+
To register these components manually, inject `BullRegistrar` and call the `register` function, ideally within `OnModuleInit` or `OnApplicationBootstrap`.
482+
483+
```typescript
484+
import { Injectable, OnModuleInit } from '@nestjs/common';
485+
import { BullRegistrar } from '@nestjs/bullmq';
486+
487+
@Injectable()
488+
export class AudioService implements OnModuleInit {
489+
constructor(private bullRegistrar: BullRegistrar) {}
490+
491+
onModuleInit() {
492+
if (yourConditionHere) {
493+
this.bullRegistrar.register();
494+
}
495+
}
496+
}
497+
```
498+
499+
Unless you call the `BullRegistrar#register` function, no BullMQ components will work—meaning no jobs will be processed.
500+
468501
#### Bull installation
469502

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

0 commit comments

Comments
 (0)