@loipv/nestjs-kafka 0.1.0 → 1.0.1
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 +254 -52
- package/dist/consumer.module.d.ts +2 -1
- package/dist/consumer.module.js +11 -7
- package/dist/consumer.module.js.map +1 -1
- package/dist/discovery/consumer-discovery.service.js.map +1 -1
- package/dist/health/kafka-health-indicator.js +7 -5
- package/dist/health/kafka-health-indicator.js.map +1 -1
- package/dist/interfaces/consumer-options.interface.d.ts +17 -4
- package/dist/interfaces/consumer-options.interface.js +2 -0
- package/dist/interfaces/consumer-options.interface.js.map +1 -1
- package/dist/interfaces/kafka-module-options.interface.d.ts +6 -4
- package/dist/interfaces/kafka-module-options.interface.js.map +1 -1
- package/dist/interfaces/message.interface.d.ts +4 -4
- package/dist/interfaces/message.interface.js.map +1 -1
- package/dist/services/batch-processor.service.d.ts +3 -1
- package/dist/services/batch-processor.service.js +0 -1
- package/dist/services/batch-processor.service.js.map +1 -1
- package/dist/services/circuit-breaker.service.js +2 -1
- package/dist/services/circuit-breaker.service.js.map +1 -1
- package/dist/services/consumer-registry.service.d.ts +4 -3
- package/dist/services/consumer-registry.service.js +210 -153
- package/dist/services/consumer-registry.service.js.map +1 -1
- package/dist/services/dlq-metrics.service.js +3 -1
- package/dist/services/dlq-metrics.service.js.map +1 -1
- package/dist/services/dlq-retry.service.js +12 -9
- package/dist/services/dlq-retry.service.js.map +1 -1
- package/dist/services/dlq.service.d.ts +3 -1
- package/dist/services/dlq.service.js.map +1 -1
- package/dist/services/idempotency.service.d.ts +3 -1
- package/dist/services/idempotency.service.js.map +1 -1
- package/dist/services/kafka-client.service.js +0 -9
- package/dist/services/kafka-client.service.js.map +1 -1
- package/dist/services/kafka-core.service.d.ts +4 -1
- package/dist/services/kafka-core.service.js +29 -32
- package/dist/services/kafka-core.service.js.map +1 -1
- package/dist/services/pressure-manager.service.d.ts +3 -1
- package/dist/services/pressure-manager.service.js.map +1 -1
- package/dist/services/tracing.service.d.ts +2 -1
- package/dist/services/tracing.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @loipv/nestjs-kafka
|
|
2
2
|
|
|
3
|
-
A production-ready NestJS module for Kafka client and consumer functionality built on top of [
|
|
3
|
+
A production-ready NestJS module for Kafka client and consumer functionality built on top of [confluent-kafka-javascript](https://github.com/confluentinc/confluent-kafka-javascript). This library provides enterprise-grade features including intelligent batch processing, idempotency guarantees, key-based grouping, and automatic pressure management.
|
|
4
|
+
|
|
5
|
+
> **Note:** Starting from v1.0.0, this library uses `@confluentinc/kafka-javascript` instead of `kafkajs` for better performance and official Confluent support. See [Migration Guide](#migration-guide-from-v0x-to-v1x) for upgrade instructions.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
@@ -18,7 +20,7 @@ A production-ready NestJS module for Kafka client and consumer functionality bui
|
|
|
18
20
|
## Installation
|
|
19
21
|
|
|
20
22
|
```bash
|
|
21
|
-
npm install @loipv/nestjs-kafka
|
|
23
|
+
npm install @loipv/nestjs-kafka @confluentinc/kafka-javascript
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
### Peer Dependencies
|
|
@@ -29,6 +31,14 @@ Make sure you have the following peer dependencies installed:
|
|
|
29
31
|
npm install @nestjs/common @nestjs/core @nestjs/terminus reflect-metadata rxjs
|
|
30
32
|
```
|
|
31
33
|
|
|
34
|
+
### Platform Support
|
|
35
|
+
|
|
36
|
+
confluent-kafka-javascript is built on librdkafka (C library). Supported platforms:
|
|
37
|
+
- **Linux**: x64, arm64
|
|
38
|
+
- **macOS**: arm64 (Apple Silicon)
|
|
39
|
+
- **Windows**: x64
|
|
40
|
+
- **Node.js**: 18, 20, 21, 22
|
|
41
|
+
|
|
32
42
|
### Optional: OpenTelemetry Tracing
|
|
33
43
|
|
|
34
44
|
For distributed tracing support:
|
|
@@ -53,7 +63,11 @@ import { OrderModule } from './order/order.module';
|
|
|
53
63
|
clientId: 'my-app',
|
|
54
64
|
brokers: ['localhost:9092'],
|
|
55
65
|
}),
|
|
56
|
-
ConsumerModule
|
|
66
|
+
// ConsumerModule with default options (applied to all @Consumer decorators)
|
|
67
|
+
ConsumerModule.forRoot({
|
|
68
|
+
partitionAssigners: ['cooperative-sticky'], // Default for all consumers
|
|
69
|
+
allowAutoTopicCreation: true, // Auto-create topics
|
|
70
|
+
}),
|
|
57
71
|
OrderModule,
|
|
58
72
|
],
|
|
59
73
|
})
|
|
@@ -80,7 +94,7 @@ export class OrderModule {}
|
|
|
80
94
|
```typescript
|
|
81
95
|
import { Injectable } from '@nestjs/common';
|
|
82
96
|
import { Consumer } from '@loipv/nestjs-kafka';
|
|
83
|
-
import { KafkaMessage } from 'kafkajs';
|
|
97
|
+
import { KafkaMessage } from '@confluentinc/kafka-javascript/kafkajs';
|
|
84
98
|
|
|
85
99
|
@Injectable()
|
|
86
100
|
export class OrderConsumer {
|
|
@@ -158,6 +172,69 @@ KafkaModule.forRootAsync({
|
|
|
158
172
|
});
|
|
159
173
|
```
|
|
160
174
|
|
|
175
|
+
### ConsumerModule Options
|
|
176
|
+
|
|
177
|
+
`ConsumerModule.forRoot()` accepts optional default options that apply to all `@Consumer` decorators. Decorator options take precedence over module defaults.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
ConsumerModule.forRoot({
|
|
181
|
+
// Partition assignment strategy (default for all consumers)
|
|
182
|
+
partitionAssigners: ['cooperative-sticky'],
|
|
183
|
+
|
|
184
|
+
// Auto-create topics if they don't exist
|
|
185
|
+
allowAutoTopicCreation: true,
|
|
186
|
+
|
|
187
|
+
// Consumer group settings
|
|
188
|
+
sessionTimeout: 30000,
|
|
189
|
+
heartbeatInterval: 3000,
|
|
190
|
+
rebalanceTimeout: 60000,
|
|
191
|
+
|
|
192
|
+
// Commit settings
|
|
193
|
+
autoCommit: true,
|
|
194
|
+
autoCommitInterval: 5000,
|
|
195
|
+
fromBeginning: false,
|
|
196
|
+
|
|
197
|
+
// Retry options
|
|
198
|
+
retry: {
|
|
199
|
+
retries: 3,
|
|
200
|
+
initialRetryTime: 1000,
|
|
201
|
+
multiplier: 2,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**How defaults work:**
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// Module defaults
|
|
210
|
+
ConsumerModule.forRoot({
|
|
211
|
+
partitionAssigners: ['cooperative-sticky'],
|
|
212
|
+
sessionTimeout: 30000,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// This consumer uses module defaults (cooperative-sticky, 30s timeout)
|
|
216
|
+
@Consumer('orders')
|
|
217
|
+
async handleOrder(message: KafkaMessage) {}
|
|
218
|
+
|
|
219
|
+
// This consumer overrides partitionAssigners but keeps sessionTimeout from defaults
|
|
220
|
+
@Consumer('events', { partitionAssigners: ['roundrobin'] })
|
|
221
|
+
async handleEvent(message: KafkaMessage) {}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**ConsumerModuleOptions:**
|
|
225
|
+
|
|
226
|
+
| Option | Type | Description |
|
|
227
|
+
|--------|------|-------------|
|
|
228
|
+
| `partitionAssigners` | `PartitionAssigner[]` | Default partition assignment strategies |
|
|
229
|
+
| `allowAutoTopicCreation` | `boolean` | Auto-create topics if not exist |
|
|
230
|
+
| `sessionTimeout` | `number` | Session timeout in ms |
|
|
231
|
+
| `heartbeatInterval` | `number` | Heartbeat interval in ms |
|
|
232
|
+
| `rebalanceTimeout` | `number` | Rebalance timeout in ms |
|
|
233
|
+
| `autoCommit` | `boolean` | Enable auto commit |
|
|
234
|
+
| `autoCommitInterval` | `number` | Auto commit interval in ms |
|
|
235
|
+
| `fromBeginning` | `boolean` | Start consuming from beginning |
|
|
236
|
+
| `retry` | `ConsumerRetryOptions` | Default retry options |
|
|
237
|
+
|
|
161
238
|
### Multi-Connection (Multiple Kafka Clusters)
|
|
162
239
|
|
|
163
240
|
Connect to multiple Kafka clusters simultaneously:
|
|
@@ -178,7 +255,7 @@ Connect to multiple Kafka clusters simultaneously:
|
|
|
178
255
|
clientId: 'my-app-analytics',
|
|
179
256
|
brokers: ['analytics-kafka:9092'],
|
|
180
257
|
}),
|
|
181
|
-
ConsumerModule,
|
|
258
|
+
ConsumerModule.forRoot(),
|
|
182
259
|
],
|
|
183
260
|
})
|
|
184
261
|
export class AppModule {}
|
|
@@ -198,7 +275,7 @@ export class AppModule {}
|
|
|
198
275
|
brokers: ['analytics-kafka:9092'],
|
|
199
276
|
},
|
|
200
277
|
]),
|
|
201
|
-
ConsumerModule,
|
|
278
|
+
ConsumerModule.forRoot(),
|
|
202
279
|
],
|
|
203
280
|
})
|
|
204
281
|
export class AppModule {}
|
|
@@ -463,6 +540,34 @@ async handleOrder(message: KafkaMessage) {
|
|
|
463
540
|
|
|
464
541
|
Use this to temporarily disable a consumer without removing the code.
|
|
465
542
|
|
|
543
|
+
### Partition Assignment Strategy
|
|
544
|
+
|
|
545
|
+
Control how partitions are assigned to consumers in a consumer group:
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
@Consumer('orders', {
|
|
549
|
+
groupId: 'order-processors',
|
|
550
|
+
// Use cooperative-sticky for minimal rebalancing disruption
|
|
551
|
+
partitionAssigners: ['cooperative-sticky'],
|
|
552
|
+
})
|
|
553
|
+
async handleOrder(message: KafkaMessage) {
|
|
554
|
+
// Process order
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Multiple strategies (first one is primary)
|
|
558
|
+
@Consumer('events', {
|
|
559
|
+
partitionAssigners: ['roundrobin', 'range'],
|
|
560
|
+
})
|
|
561
|
+
async handleEvent(message: KafkaMessage) {
|
|
562
|
+
// Process event
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
**Available strategies:**
|
|
567
|
+
- `'roundrobin'` - Assigns partitions in round-robin fashion across consumers
|
|
568
|
+
- `'range'` - Assigns partitions based on ranges (default)
|
|
569
|
+
- `'cooperative-sticky'` - Cooperative rebalancing with sticky assignment (recommended for minimal disruption during rebalancing)
|
|
570
|
+
|
|
466
571
|
### Auto-Deserialization
|
|
467
572
|
|
|
468
573
|
Messages are automatically deserialized by default:
|
|
@@ -488,9 +593,7 @@ async handleBinary(message: KafkaMessage) {
|
|
|
488
593
|
}
|
|
489
594
|
```
|
|
490
595
|
|
|
491
|
-
### Retry
|
|
492
|
-
|
|
493
|
-
#### Retry Mechanism (Without DLQ)
|
|
596
|
+
### Retry Mechanism (Without DLQ)
|
|
494
597
|
|
|
495
598
|
When **NOT using DLQ**, the library implements an in-memory retry mechanism with exponential backoff:
|
|
496
599
|
|
|
@@ -531,40 +634,6 @@ async handleLogs(message: KafkaMessagePayload) {
|
|
|
531
634
|
- Non-critical messages that can be safely dropped
|
|
532
635
|
- Development/debugging environments
|
|
533
636
|
|
|
534
|
-
#### Consumer Restart Control
|
|
535
|
-
|
|
536
|
-
Control consumer restart behavior when errors occur:
|
|
537
|
-
|
|
538
|
-
```typescript
|
|
539
|
-
// Disable restart on failure
|
|
540
|
-
@Consumer('critical-topic', {
|
|
541
|
-
retry: {
|
|
542
|
-
restartOnFailure: false,
|
|
543
|
-
},
|
|
544
|
-
})
|
|
545
|
-
async handleCritical(message: KafkaMessagePayload) {
|
|
546
|
-
// Consumer will NOT restart if this throws
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// Custom restart logic
|
|
550
|
-
@Consumer('orders', {
|
|
551
|
-
retry: {
|
|
552
|
-
retries: 10,
|
|
553
|
-
maxRetryTime: 60000,
|
|
554
|
-
restartOnFailure: async (error) => {
|
|
555
|
-
// Don't restart on authentication errors
|
|
556
|
-
if (error.message.includes('authentication')) {
|
|
557
|
-
return false;
|
|
558
|
-
}
|
|
559
|
-
return true; // Restart for other errors
|
|
560
|
-
},
|
|
561
|
-
},
|
|
562
|
-
})
|
|
563
|
-
async handleOrders(message: KafkaMessagePayload) {
|
|
564
|
-
// Process order
|
|
565
|
-
}
|
|
566
|
-
```
|
|
567
|
-
|
|
568
637
|
### All Consumer Options
|
|
569
638
|
|
|
570
639
|
```typescript
|
|
@@ -618,14 +687,15 @@ interface ConsumerOptions {
|
|
|
618
687
|
autoCommitInterval?: number;
|
|
619
688
|
fromBeginning?: boolean; // Default: false
|
|
620
689
|
|
|
621
|
-
//
|
|
690
|
+
// Partition assignment strategy
|
|
691
|
+
partitionAssigners?: PartitionAssigner[]; // 'roundrobin' | 'range' | 'cooperative-sticky'
|
|
692
|
+
|
|
693
|
+
// Retry options
|
|
622
694
|
retry?: {
|
|
623
695
|
retries?: number; // Default: 5
|
|
624
696
|
maxRetryTime?: number; // Default: 30000
|
|
625
697
|
initialRetryTime?: number; // Default: 300
|
|
626
|
-
|
|
627
|
-
multiplier?: number; // Default: 2
|
|
628
|
-
restartOnFailure?: boolean | ((error: Error) => Promise<boolean>);
|
|
698
|
+
multiplier?: number; // Default: 2 (exponential backoff)
|
|
629
699
|
skipMessageOnMaxRetries?: boolean; // Default: false (throw error after max retries)
|
|
630
700
|
};
|
|
631
701
|
}
|
|
@@ -659,13 +729,26 @@ await kafka.sendMultiTopicBatch([
|
|
|
659
729
|
await kafka.sendQueued('topic', { value: 'message' });
|
|
660
730
|
```
|
|
661
731
|
|
|
662
|
-
###
|
|
732
|
+
### Producer Options
|
|
733
|
+
|
|
734
|
+
> **Note:** In v1.0.0+, `acks`, `timeout`, and `compression` are configured at the producer level in `KafkaModule.forRoot()`, not per-send call.
|
|
663
735
|
|
|
664
736
|
```typescript
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
737
|
+
// Configure producer options at module level
|
|
738
|
+
KafkaModule.forRoot({
|
|
739
|
+
clientId: 'my-app',
|
|
740
|
+
brokers: ['localhost:9092'],
|
|
741
|
+
producer: {
|
|
742
|
+
acks: -1, // -1 (all), 0 (none), 1 (leader only)
|
|
743
|
+
timeout: 30000,
|
|
744
|
+
compression: 1, // 0=None, 1=GZIP, 2=Snappy, 3=LZ4, 4=ZSTD
|
|
745
|
+
},
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// Send messages (acks/timeout/compression configured above)
|
|
749
|
+
await kafka.send('topic', {
|
|
750
|
+
key: 'message-key',
|
|
751
|
+
value: { data: 'value' },
|
|
669
752
|
});
|
|
670
753
|
```
|
|
671
754
|
|
|
@@ -966,6 +1049,7 @@ export {
|
|
|
966
1049
|
KafkaModuleOptions,
|
|
967
1050
|
KafkaModuleAsyncOptions,
|
|
968
1051
|
TracingOptions,
|
|
1052
|
+
ConsumerModuleOptions,
|
|
969
1053
|
ConsumerOptions,
|
|
970
1054
|
DlqOptions,
|
|
971
1055
|
DlqRetryOptions,
|
|
@@ -975,6 +1059,124 @@ export {
|
|
|
975
1059
|
} from './interfaces';
|
|
976
1060
|
```
|
|
977
1061
|
|
|
1062
|
+
## Migration Guide (from v0.x to v1.x)
|
|
1063
|
+
|
|
1064
|
+
v1.0.0 introduces a **breaking change**: migrating from `kafkajs` to `@confluentinc/kafka-javascript` for better performance and official Confluent support.
|
|
1065
|
+
|
|
1066
|
+
### Why Migrate?
|
|
1067
|
+
|
|
1068
|
+
- **Performance**: confluent-kafka-javascript is built on librdkafka (C library) - significantly better performance
|
|
1069
|
+
- **Commercial Support**: Official Confluent support
|
|
1070
|
+
- **Active Development**: More active development compared to kafkajs
|
|
1071
|
+
|
|
1072
|
+
### Breaking Changes
|
|
1073
|
+
|
|
1074
|
+
#### 1. Install Dependencies
|
|
1075
|
+
|
|
1076
|
+
```bash
|
|
1077
|
+
# Remove kafkajs, add confluent-kafka-javascript
|
|
1078
|
+
npm uninstall kafkajs
|
|
1079
|
+
npm install @confluentinc/kafka-javascript
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
#### 2. Update Imports
|
|
1083
|
+
|
|
1084
|
+
```typescript
|
|
1085
|
+
// Before (v0.x)
|
|
1086
|
+
import { KafkaMessage } from 'kafkajs';
|
|
1087
|
+
|
|
1088
|
+
// After (v1.x)
|
|
1089
|
+
import { KafkaMessage } from '@confluentinc/kafka-javascript/kafkajs';
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
#### 3. Producer Options Moved to Module Level
|
|
1093
|
+
|
|
1094
|
+
`acks`, `timeout`, and `compression` are now configured at the producer level, not per-send call.
|
|
1095
|
+
|
|
1096
|
+
```typescript
|
|
1097
|
+
// Before (v0.x) - per-send options
|
|
1098
|
+
await kafka.send('topic', message, {
|
|
1099
|
+
acks: -1,
|
|
1100
|
+
timeout: 30000,
|
|
1101
|
+
compression: 1,
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
// After (v1.x) - producer-level options
|
|
1105
|
+
KafkaModule.forRoot({
|
|
1106
|
+
clientId: 'my-app',
|
|
1107
|
+
brokers: ['localhost:9092'],
|
|
1108
|
+
producer: {
|
|
1109
|
+
acks: -1,
|
|
1110
|
+
timeout: 30000,
|
|
1111
|
+
compression: 1,
|
|
1112
|
+
},
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
await kafka.send('topic', message); // No acks/timeout/compression
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
#### 4. autoCommitThreshold Removed
|
|
1119
|
+
|
|
1120
|
+
`autoCommitThreshold` is not supported in confluent-kafka-javascript. Remove this option from your consumer configuration.
|
|
1121
|
+
|
|
1122
|
+
```typescript
|
|
1123
|
+
// Before (v0.x)
|
|
1124
|
+
@Consumer('topic', {
|
|
1125
|
+
autoCommitThreshold: 100, // Not supported
|
|
1126
|
+
})
|
|
1127
|
+
|
|
1128
|
+
// After (v1.x)
|
|
1129
|
+
@Consumer('topic', {
|
|
1130
|
+
// autoCommitThreshold removed - use autoCommitInterval instead
|
|
1131
|
+
autoCommitInterval: 5000,
|
|
1132
|
+
})
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1135
|
+
#### 5. Retry Options Changes
|
|
1136
|
+
|
|
1137
|
+
The following retry options have been removed as they are not supported in confluent-kafka-javascript:
|
|
1138
|
+
|
|
1139
|
+
- `retry.restartOnFailure` - Consumer restart control is handled by the library internally
|
|
1140
|
+
- `retry.factor` - Use `retry.multiplier` for exponential backoff
|
|
1141
|
+
|
|
1142
|
+
```typescript
|
|
1143
|
+
// Before (v0.x)
|
|
1144
|
+
@Consumer('topic', {
|
|
1145
|
+
retry: {
|
|
1146
|
+
restartOnFailure: false, // Removed
|
|
1147
|
+
factor: 0.2, // Removed
|
|
1148
|
+
},
|
|
1149
|
+
})
|
|
1150
|
+
|
|
1151
|
+
// After (v1.x)
|
|
1152
|
+
@Consumer('topic', {
|
|
1153
|
+
retry: {
|
|
1154
|
+
retries: 3,
|
|
1155
|
+
multiplier: 2, // Use multiplier for backoff
|
|
1156
|
+
},
|
|
1157
|
+
})
|
|
1158
|
+
```
|
|
1159
|
+
|
|
1160
|
+
#### 6. Platform Requirements
|
|
1161
|
+
|
|
1162
|
+
confluent-kafka-javascript only supports:
|
|
1163
|
+
- **Linux**: x64, arm64
|
|
1164
|
+
- **macOS**: arm64 (Apple Silicon)
|
|
1165
|
+
- **Windows**: x64
|
|
1166
|
+
- **Node.js**: 18, 20, 21, 22
|
|
1167
|
+
|
|
1168
|
+
### No Changes Required
|
|
1169
|
+
|
|
1170
|
+
The following features work the same way:
|
|
1171
|
+
- `@Consumer()` decorator syntax
|
|
1172
|
+
- `KafkaClient.send()`, `sendBatch()`, `sendMultiTopicBatch()`, `sendQueued()`
|
|
1173
|
+
- DLQ configuration and retry
|
|
1174
|
+
- OpenTelemetry tracing
|
|
1175
|
+
- Health checks
|
|
1176
|
+
- Multi-connection support
|
|
1177
|
+
- Batch processing and key grouping
|
|
1178
|
+
- Idempotency and back pressure
|
|
1179
|
+
|
|
978
1180
|
## License
|
|
979
1181
|
|
|
980
1182
|
MIT
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { DynamicModule, OnModuleInit, OnApplicationShutdown, Type } from '@nestjs/common';
|
|
2
2
|
import { ConsumerDiscoveryService } from './discovery/consumer-discovery.service';
|
|
3
3
|
import { ConsumerRegistryService } from './services/consumer-registry.service';
|
|
4
|
+
import { ConsumerModuleOptions } from './interfaces';
|
|
4
5
|
export declare class ConsumerModule implements OnModuleInit, OnApplicationShutdown {
|
|
5
6
|
private readonly discoveryService;
|
|
6
7
|
private readonly registryService;
|
|
7
8
|
private static consumerInstances;
|
|
8
9
|
private static isStarted;
|
|
9
10
|
constructor(discoveryService: ConsumerDiscoveryService, registryService: ConsumerRegistryService);
|
|
10
|
-
static forRoot(): DynamicModule;
|
|
11
|
+
static forRoot(options?: ConsumerModuleOptions): DynamicModule;
|
|
11
12
|
static forFeature(consumers: Type<any>[]): DynamicModule;
|
|
12
13
|
static getConsumerInstances(): any[];
|
|
13
14
|
static clearConsumers(): void;
|
package/dist/consumer.module.js
CHANGED
|
@@ -21,7 +21,7 @@ const dlq_service_1 = require("./services/dlq.service");
|
|
|
21
21
|
const dlq_retry_service_1 = require("./services/dlq-retry.service");
|
|
22
22
|
const dlq_metrics_service_1 = require("./services/dlq-metrics.service");
|
|
23
23
|
const circuit_breaker_service_1 = require("./services/circuit-breaker.service");
|
|
24
|
-
const
|
|
24
|
+
const interfaces_1 = require("./interfaces");
|
|
25
25
|
const CONSUMER_PROVIDERS = [
|
|
26
26
|
consumer_discovery_service_1.ConsumerDiscoveryService,
|
|
27
27
|
consumer_registry_service_1.ConsumerRegistryService,
|
|
@@ -43,12 +43,19 @@ let ConsumerModule = class ConsumerModule {
|
|
|
43
43
|
this.discoveryService = discoveryService;
|
|
44
44
|
this.registryService = registryService;
|
|
45
45
|
}
|
|
46
|
-
static forRoot() {
|
|
46
|
+
static forRoot(options) {
|
|
47
47
|
return {
|
|
48
48
|
module: ConsumerModule_1,
|
|
49
49
|
global: true,
|
|
50
|
-
providers:
|
|
50
|
+
providers: [
|
|
51
|
+
{
|
|
52
|
+
provide: interfaces_1.CONSUMER_MODULE_OPTIONS,
|
|
53
|
+
useValue: options || {},
|
|
54
|
+
},
|
|
55
|
+
...CONSUMER_PROVIDERS,
|
|
56
|
+
],
|
|
51
57
|
exports: [
|
|
58
|
+
interfaces_1.CONSUMER_MODULE_OPTIONS,
|
|
52
59
|
consumer_discovery_service_1.ConsumerDiscoveryService,
|
|
53
60
|
consumer_registry_service_1.ConsumerRegistryService,
|
|
54
61
|
dlq_service_1.DlqService,
|
|
@@ -69,10 +76,7 @@ let ConsumerModule = class ConsumerModule {
|
|
|
69
76
|
};
|
|
70
77
|
return {
|
|
71
78
|
module: ConsumerModule_1,
|
|
72
|
-
providers: [
|
|
73
|
-
...consumers,
|
|
74
|
-
collectorProvider,
|
|
75
|
-
],
|
|
79
|
+
providers: [...consumers, collectorProvider],
|
|
76
80
|
exports: consumers,
|
|
77
81
|
};
|
|
78
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumer.module.js","sourceRoot":"","sources":["../lib/consumer.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"consumer.module.js","sourceRoot":"","sources":["../lib/consumer.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAQwB;AACxB,uFAAkF;AAClF,oFAA+E;AAC/E,gFAA2E;AAC3E,wEAAoE;AACpE,kFAA6E;AAC7E,wDAAoD;AACpD,oEAA+D;AAC/D,wEAAmE;AACnE,gFAA2E;AAC3E,6CAA8E;AAG9E,MAAM,kBAAkB,GAAe;IACrC,qDAAwB;IACxB,mDAAuB;IACvB,+CAAqB;IACrB,wCAAkB;IAClB,iDAAsB;IACtB,uCAAiB;IACjB,+CAAqB;IACrB,wBAAU;IACV,mCAAe;CAChB,CAAC;AAyBK,IAAM,cAAc,GAApB,MAAM,cAAc;;IAKN;IACA;IALX,MAAM,CAAC,iBAAiB,GAAU,EAAE,CAAC;IACrC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;IAEjC,YACmB,gBAA0C,EAC1C,eAAwC;QADxC,qBAAgB,GA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B,OAAO;QACT,CAAC;QACD,gBAAc,CAAC,SAAS,GAAG,IAAI,CAAC;QAMhC,MAAM,YAAY,GAAG,gBAAc,CAAC,oBAAoB,EAAE,CAAC;QAC3D,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;QAEvD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAClD,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;QACxC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,MAAM,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC;QAC9C,gBAAc,CAAC,cAAc,EAAE,CAAC;IAClC,CAAC;;AA1GU,wCAAc;yBAAd,cAAc;IAF1B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;qCAM4B,qDAAwB;QACzB,mDAAuB;GANhD,cAAc,CA2G1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumer-discovery.service.js","sourceRoot":"","sources":["../../lib/discovery/consumer-discovery.service.ts"],"names":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"consumer-discovery.service.js","sourceRoot":"","sources":["../../lib/discovery/consumer-discovery.service.ts"],"names":[],"mappings":";;;;;;;;;;AAEA,2CAAoD;AACpD,uDAAkE;AAElE,8CAA2E;AAGpE,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAClB,MAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAC5D,mBAAmB,GAAuB,EAAE,CAAC;IAMrD,eAAe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eAAe,QAAQ,CAAC,KAAK,EAAE,CACvG,CAAC;oBACF,SAAS;gBACX,CAAC;gBAED,MAAM,UAAU,GACd,QAAQ,CAAC,OAAO,CAAC,UAAU,IAAI,qCAAwB,CAAC;gBAE1D,MAAM,gBAAgB,GAAqB;oBACzC,KAAK,EAAE,QAAQ,CAAC,KAAK;oBACrB,UAAU;oBACV,OAAO,EAAE;wBACP,GAAG,QAAQ,CAAC,OAAO;wBACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;wBACrB,UAAU;qBACX;oBACD,MAAM,EAAE,QAAQ;oBAChB,UAAU;iBACX,CAAC;gBAEF,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBAChD,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,wBAAwB,QAAQ,CAAC,WAAW,EAAE,IAAI,IAAI,UAAU,eAAe,QAAQ,CAAC,KAAK,iBAAiB,UAAU,GAAG,CAC5H,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;CACF,CAAA;AAjGY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;GACA,wBAAwB,CAiGpC"}
|
|
@@ -32,7 +32,10 @@ let KafkaHealthIndicator = class KafkaHealthIndicator {
|
|
|
32
32
|
if (isHealthy) {
|
|
33
33
|
return indicator.up({ connected: true });
|
|
34
34
|
}
|
|
35
|
-
return indicator.down({
|
|
35
|
+
return indicator.down({
|
|
36
|
+
connected: false,
|
|
37
|
+
message: 'Kafka producer is not connected',
|
|
38
|
+
});
|
|
36
39
|
}
|
|
37
40
|
return {
|
|
38
41
|
[key]: {
|
|
@@ -46,12 +49,11 @@ let KafkaHealthIndicator = class KafkaHealthIndicator {
|
|
|
46
49
|
try {
|
|
47
50
|
const admin = this.kafkaCore.getKafka().admin();
|
|
48
51
|
await admin.connect();
|
|
49
|
-
const
|
|
52
|
+
const topics = await admin.listTopics();
|
|
50
53
|
await admin.disconnect();
|
|
51
54
|
const details = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
clusterId: clusterInfo.clusterId,
|
|
55
|
+
connected: true,
|
|
56
|
+
topicCount: topics.length,
|
|
55
57
|
};
|
|
56
58
|
if (this.healthIndicatorService) {
|
|
57
59
|
return this.healthIndicatorService.check(key).up(details);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kafka-health-indicator.js","sourceRoot":"","sources":["../../lib/health/kafka-health-indicator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,2EAA+D;AAC/D,uEAAkE;
|
|
1
|
+
{"version":3,"file":"kafka-health-indicator.js","sourceRoot":"","sources":["../../lib/health/kafka-health-indicator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsD;AACtD,2EAA+D;AAC/D,uEAAkE;AA8C3D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAEZ;IACA;IAEA;IAJnB,YACmB,WAAwB,EACxB,SAA2B,EAE3B,sBAA+C;QAH/C,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAkB;QAE3B,2BAAsB,GAAtB,sBAAsB,CAAyB;IAC/D,CAAC;IAKJ,SAAS,CAAC,GAAW;QACnB,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAE/C,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAChC,MAAM,SAAS,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACzD,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,SAAS,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC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SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrE,CAAC;YAED,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC;QACtE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC;YAEzD,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACnE,CAAC;YAED,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;CACF,CAAA;AAhHY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCAFmB,kCAAW;QACb,qCAAgB;GAHnC,oBAAoB,CAgHhC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KafkaJS } from '@confluentinc/kafka-javascript';
|
|
2
|
+
type KafkaMessage = KafkaJS.KafkaMessage;
|
|
3
|
+
export type PartitionAssigner = 'roundrobin' | 'range' | 'cooperative-sticky';
|
|
2
4
|
export interface DlqRetryOptions {
|
|
3
5
|
enabled?: boolean;
|
|
4
6
|
maxRetries?: number;
|
|
@@ -21,9 +23,7 @@ export interface ConsumerRetryOptions {
|
|
|
21
23
|
retries?: number;
|
|
22
24
|
maxRetryTime?: number;
|
|
23
25
|
initialRetryTime?: number;
|
|
24
|
-
factor?: number;
|
|
25
26
|
multiplier?: number;
|
|
26
|
-
restartOnFailure?: boolean | ((error: Error) => Promise<boolean>);
|
|
27
27
|
skipMessageOnMaxRetries?: boolean;
|
|
28
28
|
}
|
|
29
29
|
export interface ConsumerOptions {
|
|
@@ -48,9 +48,9 @@ export interface ConsumerOptions {
|
|
|
48
48
|
dlq?: DlqOptions;
|
|
49
49
|
autoCommit?: boolean;
|
|
50
50
|
autoCommitInterval?: number;
|
|
51
|
-
autoCommitThreshold?: number;
|
|
52
51
|
fromBeginning?: boolean;
|
|
53
52
|
allowAutoTopicCreation?: boolean;
|
|
53
|
+
partitionAssigners?: PartitionAssigner[];
|
|
54
54
|
retry?: ConsumerRetryOptions;
|
|
55
55
|
}
|
|
56
56
|
export interface ConsumerMetadata {
|
|
@@ -74,3 +74,16 @@ export interface PressureManagerOptions {
|
|
|
74
74
|
maxQueueSize: number;
|
|
75
75
|
checkIntervalMs?: number;
|
|
76
76
|
}
|
|
77
|
+
export interface ConsumerModuleOptions {
|
|
78
|
+
partitionAssigners?: PartitionAssigner[];
|
|
79
|
+
allowAutoTopicCreation?: boolean;
|
|
80
|
+
sessionTimeout?: number;
|
|
81
|
+
heartbeatInterval?: number;
|
|
82
|
+
rebalanceTimeout?: number;
|
|
83
|
+
autoCommit?: boolean;
|
|
84
|
+
autoCommitInterval?: number;
|
|
85
|
+
fromBeginning?: boolean;
|
|
86
|
+
retry?: ConsumerRetryOptions;
|
|
87
|
+
}
|
|
88
|
+
export declare const CONSUMER_MODULE_OPTIONS: unique symbol;
|
|
89
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumer-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/consumer-options.interface.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"consumer-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/consumer-options.interface.ts"],"names":[],"mappings":";;;AAqNa,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { KafkaJS } from '@confluentinc/kafka-javascript';
|
|
3
|
+
type SASLOptions = KafkaJS.SASLOptions;
|
|
3
4
|
export interface RetryOptions {
|
|
4
5
|
initialRetryTime?: number;
|
|
5
6
|
retries?: number;
|
|
6
7
|
maxRetryTime?: number;
|
|
7
|
-
factor?: number;
|
|
8
|
-
multiplier?: number;
|
|
9
8
|
}
|
|
10
9
|
export interface ProducerConfig {
|
|
11
|
-
createPartitioner?: () => any;
|
|
12
10
|
retry?: RetryOptions;
|
|
13
11
|
metadataMaxAge?: number;
|
|
14
12
|
allowAutoTopicCreation?: boolean;
|
|
@@ -16,6 +14,9 @@ export interface ProducerConfig {
|
|
|
16
14
|
transactionalId?: string;
|
|
17
15
|
transactionTimeout?: number;
|
|
18
16
|
maxInFlightRequests?: number;
|
|
17
|
+
acks?: -1 | 0 | 1;
|
|
18
|
+
compression?: 0 | 1 | 2 | 3 | 4;
|
|
19
|
+
timeout?: number;
|
|
19
20
|
}
|
|
20
21
|
export interface TracingOptions {
|
|
21
22
|
enabled?: boolean;
|
|
@@ -53,3 +54,4 @@ export declare const KAFKA_MODULE_OPTIONS: unique symbol;
|
|
|
53
54
|
export declare function getKafkaOptionsToken(name?: string): string;
|
|
54
55
|
export declare function getKafkaCoreToken(name?: string): string;
|
|
55
56
|
export declare function getKafkaClientToken(name?: string): string;
|
|
57
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kafka-module-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/kafka-module-options.interface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"kafka-module-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/kafka-module-options.interface.ts"],"names":[],"mappings":";;;AAkGA,oDAEC;AAGD,8CAEC;AAGD,kDAEC;AA7DY,QAAA,wBAAwB,GAAW,SAAS,CAAC;AA8C7C,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAGnE,SAAgB,oBAAoB,CAAC,IAAa;IAChD,OAAO,iBAAiB,IAAI,IAAI,gCAAwB,EAAE,CAAC;AAC7D,CAAC;AAGD,SAAgB,iBAAiB,CAAC,IAAa;IAC7C,OAAO,cAAc,IAAI,IAAI,gCAAwB,EAAE,CAAC;AAC1D,CAAC;AAGD,SAAgB,mBAAmB,CAAC,IAAa;IAC/C,OAAO,gBAAgB,IAAI,IAAI,gCAAwB,EAAE,CAAC;AAC5D,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KafkaJS } from '@confluentinc/kafka-javascript';
|
|
2
|
+
type IHeaders = KafkaJS.IHeaders;
|
|
3
|
+
type KafkaMessage = KafkaJS.KafkaMessage;
|
|
2
4
|
export interface KafkaMessagePayload<T = any> {
|
|
3
5
|
key?: string | null;
|
|
4
6
|
value: T;
|
|
@@ -20,11 +22,9 @@ export interface ProducerMessage {
|
|
|
20
22
|
timestamp?: string;
|
|
21
23
|
}
|
|
22
24
|
export interface SendOptions {
|
|
23
|
-
acks?: -1 | 0 | 1;
|
|
24
|
-
timeout?: number;
|
|
25
|
-
compression?: 0 | 1 | 2 | 3 | 4;
|
|
26
25
|
}
|
|
27
26
|
export interface GroupedBatch<T = any> {
|
|
28
27
|
key: string;
|
|
29
28
|
messages: KafkaMessagePayload<T>[];
|
|
30
29
|
}
|
|
30
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.interface.js","sourceRoot":"","sources":["../../lib/interfaces/message.interface.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"message.interface.js","sourceRoot":"","sources":["../../lib/interfaces/message.interface.ts"],"names":[],"mappings":";;AAqBA,0DAYC;AAOD,sDAUC;AAMD,gDAsBC;AAKD,gDAeC;AA7ED,SAAgB,uBAAuB,CAAC,KAAoB;IAC1D,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAA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