-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmq.module.ts
38 lines (37 loc) · 1.22 KB
/
rmq.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {DynamicModule, Module} from "@nestjs/common";
import {RabbitMQModule} from "@golevelup/nestjs-rabbitmq";
import {RmqDto} from "./rmq.dto";
import {RmqService} from "./rmq.service";
import {
DEFAULT_EXCHANGE_NAME,
DEFAULT_EXCHANGE_TYPE,
DEFAULT_PREFETCH_COUNT,
DEFAULT_TIMEOUT,
DEFAULT_WAIT
} from "./rmq.constant";
@Module({
providers: [RmqService],
exports: [RmqService]
})
export class RmqModule extends RabbitMQModule {
static register(options: RmqDto): DynamicModule {
return {
...super.forRootAsync(RabbitMQModule, {
useFactory: () => ({
exchanges: [
{
name: options.name || DEFAULT_EXCHANGE_NAME,
type: options.type || DEFAULT_EXCHANGE_TYPE,
},
],
connectionInitOptions: {
wait: options.wait || DEFAULT_WAIT,
timeout: options.timeout || DEFAULT_TIMEOUT,
},
uri: options.uri,
prefetchCount: options.prefetchCount || DEFAULT_PREFETCH_COUNT,
}),
}),
};
}
}