@bgaldino/nestjs-rabbitmq 2.0.0-beta.3 → 2.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -85
- package/dist/amqp-connection-manager.d.ts +9 -10
- package/dist/amqp-connection-manager.js +34 -58
- package/dist/amqp-connection-manager.js.map +1 -1
- package/dist/class-discovery.d.ts +2 -0
- package/dist/class-discovery.js +38 -0
- package/dist/class-discovery.js.map +1 -1
- package/dist/connection-factory.d.ts +3 -1
- package/dist/connection-factory.js +8 -0
- package/dist/connection-factory.js.map +1 -1
- package/dist/consumer-activator.service.d.ts +12 -0
- package/dist/consumer-activator.service.js +63 -0
- package/dist/consumer-activator.service.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/rabbitmq-consumer.js +1 -4
- package/dist/rabbitmq-consumer.js.map +1 -1
- package/dist/rabbitmq-service.d.ts +1 -2
- package/dist/rabbitmq-service.js +10 -8
- package/dist/rabbitmq-service.js.map +1 -1
- package/dist/rabbitmq.constants.d.ts +1 -0
- package/dist/rabbitmq.constants.js +2 -1
- package/dist/rabbitmq.constants.js.map +1 -1
- package/dist/rabbitmq.interfaces.d.ts +1 -2
- package/dist/rabbitmq.module.d.ts +13 -1
- package/dist/rabbitmq.module.js +32 -6
- package/dist/rabbitmq.module.js.map +1 -1
- package/dist/rabbitmq.types.d.ts +18 -28
- package/dist/rabbitmq.types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,11 +10,12 @@ An opinionated NestJS module for RabbitMQ with built-in retry strategies, dead l
|
|
|
10
10
|
- [forRoot](#forroot)
|
|
11
11
|
- [forRootAsync](#forrootasync)
|
|
12
12
|
- [Consumers](#consumers)
|
|
13
|
+
- [Enabling consumers](#enabling-consumers)
|
|
14
|
+
- [Selective consumer activation](#selective-consumer-activation)
|
|
13
15
|
- [Decorator-based consumers](#decorator-based-consumers)
|
|
14
16
|
- [Config-based consumers](#config-based-consumers)
|
|
15
17
|
- [Mixed usage](#mixed-usage)
|
|
16
18
|
- [Handler signature](#handler-signature)
|
|
17
|
-
- [Consumer groups](#consumer-groups)
|
|
18
19
|
- [Publishers](#publishers)
|
|
19
20
|
- [Publishing messages](#publishing-messages)
|
|
20
21
|
- [Typed publishing](#typed-publishing)
|
|
@@ -27,7 +28,6 @@ An opinionated NestJS module for RabbitMQ with built-in retry strategies, dead l
|
|
|
27
28
|
- [Disabling the automatic ack](#disabling-the-automatic-ack)
|
|
28
29
|
- [Custom Header Metadata](#custom-header-metadata)
|
|
29
30
|
- [Extra Options](#extra-options)
|
|
30
|
-
- [Consumer manual loading](#consumer-manual-loading)
|
|
31
31
|
- [Message inspection and logging](#message-inspection-and-logging)
|
|
32
32
|
- [Health check](#health-check)
|
|
33
33
|
- [Building locally](#building-locally)
|
|
@@ -57,8 +57,13 @@ and dead letter exchanges instead of the delayed message plugin.
|
|
|
57
57
|
|
|
58
58
|
## Getting Started
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
to inject `RabbitMQService` anywhere in your application.
|
|
60
|
+
`RabbitMQModule.forRoot()` is marked as `@Global`, so importing it once is
|
|
61
|
+
enough to inject `RabbitMQService` anywhere in your application. It handles
|
|
62
|
+
connections and publishing.
|
|
63
|
+
|
|
64
|
+
To enable consumers, import `RabbitMQModule.withConsumers()` alongside
|
|
65
|
+
`forRoot()`. Without it, only publisher connections are opened and no messages
|
|
66
|
+
are consumed.
|
|
62
67
|
|
|
63
68
|
### forRoot
|
|
64
69
|
|
|
@@ -77,6 +82,7 @@ import { RabbitMQModule } from '@bgaldino/nestjs-rabbitmq';
|
|
|
77
82
|
{ name: 'notifications', type: 'fanout' },
|
|
78
83
|
],
|
|
79
84
|
}),
|
|
85
|
+
RabbitMQModule.withConsumers(),
|
|
80
86
|
],
|
|
81
87
|
})
|
|
82
88
|
export class AppModule {}
|
|
@@ -139,6 +145,81 @@ All queues are created as [quorum queues](https://www.rabbitmq.com/docs/quorum-q
|
|
|
139
145
|
by default. Consumers do not create exchanges, they only bind to exchanges
|
|
140
146
|
that already exist (declared via `assertExchanges`).
|
|
141
147
|
|
|
148
|
+
Consumers are only activated when `RabbitMQModule.withConsumers()` is imported.
|
|
149
|
+
Without it, no consumer connections are opened and no messages are consumed.
|
|
150
|
+
|
|
151
|
+
### Enabling consumers
|
|
152
|
+
|
|
153
|
+
Import `withConsumers()` alongside `forRoot()` to enable consumer discovery
|
|
154
|
+
and activation. The no-arg form discovers all `@RabbitConsumer` decorated
|
|
155
|
+
methods across the application and processes all `consumerChannels` from the
|
|
156
|
+
connection config:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
@Module({
|
|
160
|
+
imports: [
|
|
161
|
+
RabbitMQModule.forRoot({ ... }),
|
|
162
|
+
RabbitMQModule.withConsumers(),
|
|
163
|
+
],
|
|
164
|
+
})
|
|
165
|
+
export class AppModule {}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Selective consumer activation
|
|
169
|
+
|
|
170
|
+
When your application has multiple deployments (e.g., an API server and a
|
|
171
|
+
background worker), you can pass explicit handler classes to `withConsumers()`
|
|
172
|
+
to control which consumers are activated in each deployment:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// API deployment — publish only, no consumers
|
|
176
|
+
@Module({
|
|
177
|
+
imports: [
|
|
178
|
+
RabbitMQModule.forRoot({ ... }),
|
|
179
|
+
],
|
|
180
|
+
})
|
|
181
|
+
export class ApiAppModule {}
|
|
182
|
+
|
|
183
|
+
// Worker deployment — only order and payment consumers
|
|
184
|
+
@Module({
|
|
185
|
+
imports: [
|
|
186
|
+
RabbitMQModule.forRoot({ ... }),
|
|
187
|
+
RabbitMQModule.withConsumers([OrderHandler, PaymentHandler]),
|
|
188
|
+
],
|
|
189
|
+
})
|
|
190
|
+
export class WorkerAppModule {}
|
|
191
|
+
|
|
192
|
+
// Report deployment — only report consumers
|
|
193
|
+
@Module({
|
|
194
|
+
imports: [
|
|
195
|
+
RabbitMQModule.forRoot({ ... }),
|
|
196
|
+
RabbitMQModule.withConsumers([ReportHandler]),
|
|
197
|
+
],
|
|
198
|
+
})
|
|
199
|
+
export class ReportAppModule {}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
When handler classes are passed, only `@RabbitConsumer` methods on those
|
|
203
|
+
classes are activated. Config consumers (`consumerChannels`) are always
|
|
204
|
+
processed regardless.
|
|
205
|
+
|
|
206
|
+
Keep in mind that all `@RabbitConsumer` methods on a given class are
|
|
207
|
+
activated together. If a class has consumers meant for different deployments,
|
|
208
|
+
split it into separate classes — one per deployment concern:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// Each class serves a single deployment
|
|
212
|
+
class OrderCreateHandler {
|
|
213
|
+
@RabbitConsumer({ queue: 'orders.create', ... })
|
|
214
|
+
async handle() { ... }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
class OrderReportHandler {
|
|
218
|
+
@RabbitConsumer({ queue: 'orders.report', ... })
|
|
219
|
+
async handle() { ... }
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
142
223
|
### Decorator-based consumers
|
|
143
224
|
|
|
144
225
|
Decorate any method with `@RabbitConsumer()` and the library will
|
|
@@ -252,32 +333,6 @@ export class OrderService implements ConsumerHandler<OrderPayload> {
|
|
|
252
333
|
}
|
|
253
334
|
```
|
|
254
335
|
|
|
255
|
-
### Consumer groups
|
|
256
|
-
|
|
257
|
-
Groups allow you to control which consumers are enabled on a given deployment.
|
|
258
|
-
This is useful when multiple instances of the same application serve different
|
|
259
|
-
roles.
|
|
260
|
-
|
|
261
|
-
```typescript
|
|
262
|
-
@RabbitConsumer({
|
|
263
|
-
queue: 'heavy.processing',
|
|
264
|
-
exchangeName: 'jobs',
|
|
265
|
-
routingKey: 'heavy.*',
|
|
266
|
-
group: 'workers',
|
|
267
|
-
})
|
|
268
|
-
async processHeavyJob(content: any) { ... }
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
The active group is determined by:
|
|
272
|
-
|
|
273
|
-
1. The `RMQ_CONSUMER_GROUP` environment variable (highest priority)
|
|
274
|
-
2. The `group` parameter passed to `createConsumers(group)`
|
|
275
|
-
3. Defaults to `"rabbit-default"`
|
|
276
|
-
|
|
277
|
-
Consumers without an explicit group are assigned to the active group and will
|
|
278
|
-
always be initialized. Consumers with a group that does not match the active
|
|
279
|
-
group are skipped.
|
|
280
|
-
|
|
281
336
|
## Publishers
|
|
282
337
|
|
|
283
338
|
### Publishing messages
|
|
@@ -445,6 +500,13 @@ before the next retry. The return value controls the behavior:
|
|
|
445
500
|
- `maxAttempts`: 5
|
|
446
501
|
- `delay`: () => 5000
|
|
447
502
|
|
|
503
|
+
You can also give a "string" value referring a method of the same class,
|
|
504
|
+
following the interface:
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
function retry(content: any, attempt: number, exception: Error): Promise<number> | number;
|
|
508
|
+
```
|
|
509
|
+
|
|
448
510
|
When the maximum number of attempts is reached, the message is nacked and sent
|
|
449
511
|
to the dead letter queue.
|
|
450
512
|
|
|
@@ -480,28 +542,13 @@ the raw message content and should return a boolean:
|
|
|
480
542
|
|
|
481
543
|
If the callback throws an error, the message is forwarded to the DLQ regardless.
|
|
482
544
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
By default, the consumer automatically acknowledges the message after the
|
|
486
|
-
handler completes. If you need manual control over acknowledgement, disable it:
|
|
545
|
+
Like the `retryStrategy`, you can pass a "string" of the method name you want
|
|
546
|
+
to call if it is in the same class. The method should implement the interface:
|
|
487
547
|
|
|
488
548
|
```typescript
|
|
489
|
-
|
|
490
|
-
queue: 'order.process',
|
|
491
|
-
exchangeName: 'orders',
|
|
492
|
-
routingKey: 'order.process',
|
|
493
|
-
autoAck: false,
|
|
494
|
-
})
|
|
495
|
-
async processOrder(content: OrderPayload, params: MessageParams) {
|
|
496
|
-
// do work
|
|
497
|
-
params.channel.ack(params.message);
|
|
498
|
-
}
|
|
549
|
+
function (content: T): Promise<boolean> | boolean;
|
|
499
550
|
```
|
|
500
551
|
|
|
501
|
-
When `autoAck` is disabled, you are responsible for calling `channel.ack()` or
|
|
502
|
-
`channel.nack()`. If you do not acknowledge the message, it will remain
|
|
503
|
-
unacknowledged and RabbitMQ will redeliver it when the consumer disconnects.
|
|
504
|
-
|
|
505
552
|
## Custom Header Metadata
|
|
506
553
|
|
|
507
554
|
Every published message includes the following custom headers automatically:
|
|
@@ -523,41 +570,6 @@ when available, falling back to the message's current routing key.
|
|
|
523
570
|
|
|
524
571
|
## Extra Options
|
|
525
572
|
|
|
526
|
-
### Consumer manual loading
|
|
527
|
-
|
|
528
|
-
Consumers are attached during the `OnApplicationBootstrap` lifecycle, which
|
|
529
|
-
means the application begins receiving messages as soon as all modules are
|
|
530
|
-
initialized, but before `app.listen()` resolves.
|
|
531
|
-
|
|
532
|
-
If you need consumers to start only after the HTTP server is ready (or need
|
|
533
|
-
to defer startup for any other reason), set `consumerManualLoad: true` and
|
|
534
|
-
call the initialization manually:
|
|
535
|
-
|
|
536
|
-
```typescript
|
|
537
|
-
RabbitMQModule.forRoot({
|
|
538
|
-
connectionString: 'amqp://localhost',
|
|
539
|
-
delayExchangeName: 'my_app',
|
|
540
|
-
assertExchanges: [],
|
|
541
|
-
extraOptions: {
|
|
542
|
-
consumerManualLoad: true,
|
|
543
|
-
},
|
|
544
|
-
})
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
```typescript
|
|
548
|
-
async function bootstrap() {
|
|
549
|
-
const app = await NestFactory.create(AppModule);
|
|
550
|
-
await app.listen(3000);
|
|
551
|
-
|
|
552
|
-
const rabbit = app.get(RabbitMQService);
|
|
553
|
-
await rabbit.startConsumers();
|
|
554
|
-
}
|
|
555
|
-
bootstrap();
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
You can also pass a group name to `startConsumers(group)` to initialize only consumers
|
|
559
|
-
belonging to that group.
|
|
560
|
-
|
|
561
573
|
### Message inspection and logging
|
|
562
574
|
|
|
563
575
|
You can inspect consumer and publisher messages by setting `extraOptions.logType`
|
|
@@ -581,12 +593,15 @@ connections:
|
|
|
581
593
|
const rabbit = app.get(RabbitMQService);
|
|
582
594
|
|
|
583
595
|
// Check all connections (returns 0 if any connection is offline)
|
|
584
|
-
const status = rabbit.checkHealth(); // 1 = online, 0 = offline
|
|
596
|
+
const status = await rabbit.checkHealth(); // 1 = online, 0 = offline
|
|
585
597
|
|
|
586
598
|
// Check a specific connection
|
|
587
|
-
const sharedStatus = rabbit.checkHealth('shared-bus');
|
|
599
|
+
const sharedStatus = await rabbit.checkHealth('shared-bus');
|
|
588
600
|
```
|
|
589
601
|
|
|
602
|
+
When `withConsumers()` is not imported, the health check only verifies
|
|
603
|
+
publisher connections.
|
|
604
|
+
|
|
590
605
|
## Building locally
|
|
591
606
|
|
|
592
607
|
```shell
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LogType, ModuleOptions } from "./rabbitmq.types";
|
|
3
|
-
import { ClassDiscovery } from "./class-discovery";
|
|
1
|
+
import { OnApplicationShutdown, OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { LogType, ModuleOptions, RabbitMQConsumerResolved } from "./rabbitmq.types";
|
|
4
3
|
import { ConnectionHolder } from "./connection-factory";
|
|
5
|
-
export declare class AMQPConnectionManager implements OnModuleInit,
|
|
6
|
-
private readonly classDiscovery;
|
|
4
|
+
export declare class AMQPConnectionManager implements OnModuleInit, OnApplicationShutdown {
|
|
7
5
|
private readonly logger;
|
|
8
6
|
private defaultOptions;
|
|
9
7
|
private opts;
|
|
10
8
|
private connections;
|
|
11
9
|
private connectionFactory;
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
private resolveConnection;
|
|
11
|
+
private readonly connectionReady;
|
|
12
|
+
constructor(options: ModuleOptions);
|
|
14
13
|
onModuleInit(): Promise<void>;
|
|
15
|
-
|
|
14
|
+
private connectPublishers;
|
|
16
15
|
getLogType(): LogType;
|
|
16
|
+
ensureConnected(): Promise<void>;
|
|
17
17
|
getConnectionHolder(name?: string): ConnectionHolder;
|
|
18
18
|
getAllConnections(): ConnectionHolder[];
|
|
19
|
-
|
|
19
|
+
activateConsumers(consumers: RabbitMQConsumerResolved[]): Promise<void>;
|
|
20
20
|
onApplicationShutdown(): Promise<void>;
|
|
21
21
|
private resolveConnections;
|
|
22
|
-
private connect;
|
|
23
22
|
private buildConsumer;
|
|
24
23
|
}
|
|
@@ -18,93 +18,76 @@ const common_1 = require("@nestjs/common");
|
|
|
18
18
|
const helper_1 = require("./helper");
|
|
19
19
|
const rabbitmq_consumer_1 = require("./rabbitmq-consumer");
|
|
20
20
|
const rabbitmq_constants_1 = require("./rabbitmq.constants");
|
|
21
|
-
const class_discovery_1 = require("./class-discovery");
|
|
22
21
|
const connection_factory_1 = require("./connection-factory");
|
|
23
22
|
let AMQPConnectionManager = AMQPConnectionManager_1 = class AMQPConnectionManager {
|
|
24
|
-
constructor(options
|
|
23
|
+
constructor(options) {
|
|
25
24
|
var _a, _b;
|
|
26
|
-
this.
|
|
25
|
+
this.logger = new common_1.Logger(AMQPConnectionManager_1.name);
|
|
27
26
|
this.defaultOptions = {
|
|
28
27
|
extraOptions: {
|
|
29
28
|
logType: "none",
|
|
30
|
-
consumerManualLoad: false,
|
|
31
29
|
heartbeatIntervalInSeconds: 0,
|
|
32
30
|
reconnectTimeInSeconds: 5,
|
|
33
31
|
},
|
|
34
32
|
};
|
|
35
33
|
this.connections = new Map();
|
|
36
|
-
this.consumerInitialized = false;
|
|
37
34
|
this.opts = (0, helper_1.merge)(this.defaultOptions, options);
|
|
38
35
|
this.opts.extraOptions.logType = (_b = (_a = process.env) === null || _a === void 0 ? void 0 : _a.RABBITMQ_LOG_TYPE) !== null && _b !== void 0 ? _b : this.opts.extraOptions.logType;
|
|
39
|
-
this.logger = new common_1.Logger(AMQPConnectionManager_1.name);
|
|
40
36
|
this.connectionFactory = new connection_factory_1.ConnectionFactory(this.opts);
|
|
37
|
+
this.connectionReady = new Promise(resolve => {
|
|
38
|
+
this.resolveConnection = resolve;
|
|
39
|
+
});
|
|
41
40
|
}
|
|
42
41
|
async onModuleInit() {
|
|
43
|
-
|
|
42
|
+
await this.connectPublishers();
|
|
43
|
+
this.resolveConnection();
|
|
44
44
|
}
|
|
45
|
-
async
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
async connectPublishers() {
|
|
46
|
+
const configs = this.resolveConnections();
|
|
47
|
+
for (const config of configs) {
|
|
48
|
+
const holder = await this.connectionFactory.createPublisher(config);
|
|
49
|
+
this.connections.set(config.name, holder);
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
getLogType() {
|
|
52
53
|
return this.opts.extraOptions.logType;
|
|
53
54
|
}
|
|
55
|
+
async ensureConnected() {
|
|
56
|
+
await this.connectionReady;
|
|
57
|
+
}
|
|
54
58
|
getConnectionHolder(name = "default") {
|
|
55
59
|
const holder = this.connections.get(name);
|
|
56
60
|
if (!holder) {
|
|
57
|
-
|
|
61
|
+
const available = [...this.connections.keys()];
|
|
62
|
+
const hint = available.length === 0
|
|
63
|
+
? " Connections may not have been established yet. Ensure RabbitMQModule is imported before modules that depend on it."
|
|
64
|
+
: "";
|
|
65
|
+
throw new Error(`RabbitMQModule: Connection "${name}" not found. Available: ${available.join(", ")}.${hint}`);
|
|
58
66
|
}
|
|
59
67
|
return holder;
|
|
60
68
|
}
|
|
61
69
|
getAllConnections() {
|
|
62
70
|
return [...this.connections.values()];
|
|
63
71
|
}
|
|
64
|
-
async
|
|
65
|
-
var _a
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.logger.log(`Initializing consumers with group: ${consumerGroup}`);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.logger.log(`No groups associated, initializing all consumers without groups`);
|
|
74
|
-
}
|
|
75
|
-
const allConsumers = [];
|
|
76
|
-
for (const [connName, holder] of this.connections) {
|
|
77
|
-
const configConsumers = this.classDiscovery
|
|
78
|
-
.getConfigConsumers((_f = holder.config.consumerChannels) !== null && _f !== void 0 ? _f : [])
|
|
79
|
-
.map(c => (Object.assign(Object.assign({}, c), { connection: connName })));
|
|
80
|
-
allConsumers.push(...configConsumers);
|
|
72
|
+
async activateConsumers(consumers) {
|
|
73
|
+
var _a;
|
|
74
|
+
for (const [, holder] of this.connections) {
|
|
75
|
+
if (!holder.consumerConn) {
|
|
76
|
+
await this.connectionFactory.attachConsumer(holder);
|
|
77
|
+
}
|
|
81
78
|
}
|
|
82
|
-
const decoratorConsumers = this.classDiscovery.discoverDecoratedConsumers();
|
|
83
|
-
allConsumers.push(...decoratorConsumers);
|
|
84
79
|
const dupQueues = new Set();
|
|
85
|
-
for (const c of
|
|
86
|
-
if (dupQueues.has(c.queue))
|
|
87
|
-
throw new Error(`
|
|
88
|
-
}
|
|
80
|
+
for (const c of consumers) {
|
|
81
|
+
if (dupQueues.has(c.queue))
|
|
82
|
+
throw new Error(`Duplicate queue "${c.queue}"`);
|
|
89
83
|
dupQueues.add(c.queue);
|
|
90
84
|
}
|
|
91
|
-
for (const consumer of
|
|
92
|
-
|
|
93
|
-
if (consumer.group !== consumerGroup)
|
|
94
|
-
continue;
|
|
95
|
-
if (consumer.enabled === false) {
|
|
96
|
-
this.logger.debug({ type: "initialization", title: `[AMQP] [INIT] Consumer ${consumer.queue} is DISABLED` });
|
|
85
|
+
for (const consumer of consumers) {
|
|
86
|
+
if (consumer.enabled === false)
|
|
97
87
|
continue;
|
|
98
|
-
|
|
99
|
-
const connName = (_h = consumer.connection) !== null && _h !== void 0 ? _h : "default";
|
|
88
|
+
const connName = (_a = consumer.connection) !== null && _a !== void 0 ? _a : "default";
|
|
100
89
|
await this.buildConsumer(connName).createConsumer(consumer, consumer.handler);
|
|
101
|
-
this.logger.debug({
|
|
102
|
-
type: "initialization",
|
|
103
|
-
title: `[AMQP] [INIT] Initializing consumer ${consumer.queue}`,
|
|
104
|
-
binding: { exchange: consumer.exchangeName, routingKey: consumer.routingKey, group: consumer.group },
|
|
105
|
-
});
|
|
106
90
|
}
|
|
107
|
-
this.consumerInitialized = true;
|
|
108
91
|
}
|
|
109
92
|
async onApplicationShutdown() {
|
|
110
93
|
var _a, _b;
|
|
@@ -134,13 +117,6 @@ let AMQPConnectionManager = AMQPConnectionManager_1 = class AMQPConnectionManage
|
|
|
134
117
|
consumerChannels: this.opts.consumerChannels,
|
|
135
118
|
}];
|
|
136
119
|
}
|
|
137
|
-
async connect() {
|
|
138
|
-
const configs = this.resolveConnections();
|
|
139
|
-
for (const config of configs) {
|
|
140
|
-
const holder = await this.connectionFactory.create(config);
|
|
141
|
-
this.connections.set(config.name, holder);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
120
|
buildConsumer(connectionName = "default") {
|
|
145
121
|
const holder = this.getConnectionHolder(connectionName);
|
|
146
122
|
return new rabbitmq_consumer_1.RabbitMQConsumer(holder.consumerConn, holder.config.delayExchangeName, this.opts.extraOptions.logType, holder.publisherWrapper);
|
|
@@ -150,6 +126,6 @@ exports.AMQPConnectionManager = AMQPConnectionManager;
|
|
|
150
126
|
exports.AMQPConnectionManager = AMQPConnectionManager = AMQPConnectionManager_1 = __decorate([
|
|
151
127
|
(0, common_1.Injectable)(),
|
|
152
128
|
__param(0, (0, common_1.Inject)(rabbitmq_constants_1.RABBIT_OPTIONS)),
|
|
153
|
-
__metadata("design:paramtypes", [Object
|
|
129
|
+
__metadata("design:paramtypes", [Object])
|
|
154
130
|
], AMQPConnectionManager);
|
|
155
131
|
//# sourceMappingURL=amqp-connection-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amqp-connection-manager.js","sourceRoot":"","sources":["../src/amqp-connection-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"amqp-connection-manager.js","sourceRoot":"","sources":["../src/amqp-connection-manager.ts"],"names":[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GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAClE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,8CAA8C,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACnF,CAAC;YACD,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;QAC/B,CAAC;QAED,OAAO,CAAC;gBACN,IAAI,EAAE,SAAS;gBACf,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB;gBAC5C,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,iBAAiB;gBAC9C,eAAe,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe;gBAC1C,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB;aAC7C,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,iBAAyB,SAAS;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACxD,OAAO,IAAI,oCAAgB,CACzB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAC/B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAC9B,MAAM,CAAC,gBAAgB,CACxB,CAAC;IACJ,CAAC;CACF,CAAA;AAtIY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAkBR,WAAA,IAAA,eAAM,EAAC,mCAAc,CAAC,CAAA;;GAjBd,qBAAqB,CAsIjC"}
|
|
@@ -9,5 +9,7 @@ export declare class ClassDiscovery {
|
|
|
9
9
|
constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector);
|
|
10
10
|
getProviderInstance<T>(provider: Type<T>): T;
|
|
11
11
|
discoverDecoratedConsumers(): Array<RabbitMQConsumerResolved>;
|
|
12
|
+
discoverFromClasses(classes: Type[]): Array<RabbitMQConsumerResolved>;
|
|
12
13
|
getConfigConsumers(consumerList: Array<ConsumerChannel>): Array<RabbitMQConsumerResolved>;
|
|
14
|
+
private resolveStrategyMethods;
|
|
13
15
|
}
|
package/dist/class-discovery.js
CHANGED
|
@@ -49,6 +49,26 @@ let ClassDiscovery = class ClassDiscovery {
|
|
|
49
49
|
const meta = this.reflector.get(rabbit_consumer_decorator_1.RABBIT_HANDLER_METADATA, instance[method]);
|
|
50
50
|
if (!meta)
|
|
51
51
|
continue;
|
|
52
|
+
this.resolveStrategyMethods(meta, instance);
|
|
53
|
+
discovered.push(Object.assign(Object.assign({}, meta), { handler: instance[method].bind(instance) }));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return discovered;
|
|
57
|
+
}
|
|
58
|
+
discoverFromClasses(classes) {
|
|
59
|
+
const discovered = [];
|
|
60
|
+
for (const cls of classes) {
|
|
61
|
+
const wrapper = this.wrappers.find(w => w.metatype === cls);
|
|
62
|
+
if (!(wrapper === null || wrapper === void 0 ? void 0 : wrapper.instance)) {
|
|
63
|
+
throw new Error(`RabbitMQModule: Provider ${cls.name} not found. Is it registered in a module?`);
|
|
64
|
+
}
|
|
65
|
+
const { instance } = wrapper;
|
|
66
|
+
const methods = this.metadataScanner.getAllMethodNames(instance);
|
|
67
|
+
for (const method of methods) {
|
|
68
|
+
const meta = this.reflector.get(rabbit_consumer_decorator_1.RABBIT_HANDLER_METADATA, instance[method]);
|
|
69
|
+
if (!meta)
|
|
70
|
+
continue;
|
|
71
|
+
this.resolveStrategyMethods(meta, instance);
|
|
52
72
|
discovered.push(Object.assign(Object.assign({}, meta), { handler: instance[method].bind(instance) }));
|
|
53
73
|
}
|
|
54
74
|
}
|
|
@@ -67,6 +87,24 @@ let ClassDiscovery = class ClassDiscovery {
|
|
|
67
87
|
}
|
|
68
88
|
return consumers;
|
|
69
89
|
}
|
|
90
|
+
resolveStrategyMethods(meta, instance) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const className = instance.constructor.name;
|
|
93
|
+
if (typeof ((_a = meta.retryStrategy) === null || _a === void 0 ? void 0 : _a.delay) === "string") {
|
|
94
|
+
const fn = instance[meta.retryStrategy.delay];
|
|
95
|
+
if (typeof fn !== "function") {
|
|
96
|
+
throw new Error(`RabbitMQModule: Method "${meta.retryStrategy.delay}" not found on ${className}`);
|
|
97
|
+
}
|
|
98
|
+
meta.retryStrategy.delay = fn.bind(instance);
|
|
99
|
+
}
|
|
100
|
+
if (typeof ((_b = meta.deadLetterStrategy) === null || _b === void 0 ? void 0 : _b.callback) === "string") {
|
|
101
|
+
const fn = instance[meta.deadLetterStrategy.callback];
|
|
102
|
+
if (typeof fn !== "function") {
|
|
103
|
+
throw new Error(`RabbitMQModule: Method "${meta.deadLetterStrategy.callback}" not found on ${className}`);
|
|
104
|
+
}
|
|
105
|
+
meta.deadLetterStrategy.callback = fn.bind(instance);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
70
108
|
};
|
|
71
109
|
exports.ClassDiscovery = ClassDiscovery;
|
|
72
110
|
exports.ClassDiscovery = ClassDiscovery = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-discovery.js","sourceRoot":"","sources":["../src/class-discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAkD;AAClD,uCAA4E;AAE5E,2EAAsE;AAI/D,IAAM,cAAc,GAApB,MAAM,cAAc;
|
|
1
|
+
{"version":3,"file":"class-discovery.js","sourceRoot":"","sources":["../src/class-discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAkD;AAClD,uCAA4E;AAE5E,2EAAsE;AAI/D,IAAM,cAAc,GAApB,MAAM,cAAc;IAGzB,YACmB,gBAAkC,EAClC,eAAgC,EAChC,SAAoB;QAFpB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC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QAED,IAAI,OAAO,CAAA,MAAA,IAAI,CAAC,kBAAkB,0CAAE,QAAQ,CAAA,KAAK,QAAQ,EAAE,CAAC;YAC1D,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;YACtD,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,CAAC,kBAAkB,CAAC,QAAQ,kBAAkB,SAAS,EAAE,CAAC,CAAC;YAC5G,CAAC;YACD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF,CAAA;AArHY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAK0B,uBAAgB;QACjB,sBAAe;QACrB,gBAAS;GAN5B,cAAc,CAqH1B"}
|
|
@@ -2,7 +2,7 @@ import { AmqpConnectionManager, ChannelWrapper } from "amqp-connection-manager";
|
|
|
2
2
|
import { ConnectionConfig, ModuleOptions } from "./rabbitmq.types";
|
|
3
3
|
export type ConnectionHolder = {
|
|
4
4
|
config: ConnectionConfig;
|
|
5
|
-
consumerConn: AmqpConnectionManager;
|
|
5
|
+
consumerConn: AmqpConnectionManager | null;
|
|
6
6
|
publisherConn: AmqpConnectionManager;
|
|
7
7
|
publisherWrapper: ChannelWrapper;
|
|
8
8
|
};
|
|
@@ -12,6 +12,8 @@ export declare class ConnectionFactory {
|
|
|
12
12
|
private readonly terminalErrors;
|
|
13
13
|
constructor(opts: ModuleOptions);
|
|
14
14
|
create(config: ConnectionConfig): Promise<ConnectionHolder>;
|
|
15
|
+
createPublisher(config: ConnectionConfig): Promise<ConnectionHolder>;
|
|
16
|
+
attachConsumer(holder: ConnectionHolder): Promise<void>;
|
|
15
17
|
private connectBroker;
|
|
16
18
|
private awaitConnection;
|
|
17
19
|
private registerConnectionEvents;
|
|
@@ -22,6 +22,14 @@ class ConnectionFactory {
|
|
|
22
22
|
const publisherWrapper = await this.assertExchanges(publisherConn, config);
|
|
23
23
|
return { config, consumerConn, publisherConn, publisherWrapper };
|
|
24
24
|
}
|
|
25
|
+
async createPublisher(config) {
|
|
26
|
+
const publisherConn = await this.connectBroker(config, "publisher");
|
|
27
|
+
const publisherWrapper = await this.assertExchanges(publisherConn, config);
|
|
28
|
+
return { config, consumerConn: null, publisherConn, publisherWrapper };
|
|
29
|
+
}
|
|
30
|
+
async attachConsumer(holder) {
|
|
31
|
+
holder.consumerConn = await this.connectBroker(holder.config, "consumer");
|
|
32
|
+
}
|
|
25
33
|
async connectBroker(config, type) {
|
|
26
34
|
const conn = (0, amqp_connection_manager_1.connect)(config.connectionString, this.buildConnectionOptions(`${config.name}-${type}`));
|
|
27
35
|
await this.awaitConnection(conn, config.name, type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-factory.js","sourceRoot":"","sources":["../src/connection-factory.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,qEAIiC;AAEjC,qCAAmC;AAUnC,MAAa,iBAAiB;IAU5B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;QAT/B,WAAM,GAAG,IAAI,eAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC5C,mBAAc,GAAa;YAC1C,eAAe;YACf,qBAAqB;YACrB,aAAa;YACb,gBAAgB;YAChB,8BAA8B;SAC/B,CAAC;IAEkD,CAAC;IAErD,KAAK,CAAC,MAAM,CAAC,MAAwB;QACnC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAClE,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACpE,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,MAAM,CAAC,C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AAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,2BAA2B,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC3E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,KAAK,MAAM,QAAQ,IAAI,MAAA,MAAM,CAAC,eAAe,mCAAI,EAAE,EAAE,CAAC;YACpD,MAAM,OAAO,CAAC,QAAQ,CACpB,KAAK,EAAE,OAAuB,EAAE,EAAE;;gBAChC,MAAM,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;oBACzD,OAAO,EAAE,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,0CAAE,OAAO,mCAAI,IAAI;oBAC3C,UAAU,EAAE,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,0CAAE,UAAU,mCAAI,KAAK;iBACnD,CAAC,CAAC;YACL,CAAC,CACF,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAnID,8CAmIC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OnApplicationBootstrap, Type } from "@nestjs/common";
|
|
2
|
+
import { AMQPConnectionManager } from "./amqp-connection-manager";
|
|
3
|
+
import { ClassDiscovery } from "./class-discovery";
|
|
4
|
+
export declare class ConsumerActivator implements OnApplicationBootstrap {
|
|
5
|
+
private readonly connManager;
|
|
6
|
+
private readonly classDiscovery;
|
|
7
|
+
private readonly handlers;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(connManager: AMQPConnectionManager, classDiscovery: ClassDiscovery, handlers: Type[] | null);
|
|
10
|
+
onApplicationBootstrap(): Promise<void>;
|
|
11
|
+
private discoverConsumers;
|
|
12
|
+
}
|