@twt-494/nestjs-kafka 6.0.0 → 6.0.2
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/dist/kafka.service.d.ts +7 -5
- package/dist/kafka.service.js +8 -3
- package/package.json +1 -1
package/dist/kafka.service.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { Consumer } from 'kafkajs';
|
|
3
3
|
import { KafkaModuleOptions } from './kafka.module';
|
|
4
|
-
export declare class KafkaService implements OnModuleInit
|
|
4
|
+
export declare class KafkaService implements OnModuleInit {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private kafka;
|
|
7
7
|
private producer;
|
|
8
8
|
constructor(options: KafkaModuleOptions);
|
|
9
9
|
onModuleInit(): Promise<void>;
|
|
10
|
-
|
|
11
|
-
createConsumer(topic: string
|
|
10
|
+
shutdown(): Promise<void>;
|
|
11
|
+
createConsumer(topic: string, options?: {
|
|
12
|
+
sessionTimeout?: number;
|
|
13
|
+
}): Promise<Consumer>;
|
|
12
14
|
sendBatch(topic: string, data: {
|
|
13
15
|
key?: string;
|
|
14
16
|
value: string;
|
|
15
17
|
}[]): Promise<void>;
|
|
16
|
-
send(topic: string, data:
|
|
18
|
+
send(topic: string, data: any, key?: string): Promise<void>;
|
|
17
19
|
produceBatch(topic: string, messages: {
|
|
18
20
|
value: string;
|
|
19
21
|
key?: string;
|
package/dist/kafka.service.js
CHANGED
|
@@ -32,12 +32,17 @@ let KafkaService = class KafkaService {
|
|
|
32
32
|
createPartitioner: kafkajs_1.Partitioners.LegacyPartitioner,
|
|
33
33
|
});
|
|
34
34
|
await this.producer.connect();
|
|
35
|
+
process.on('SIGTERM', this.shutdown);
|
|
36
|
+
process.on('SIGINT', this.shutdown);
|
|
35
37
|
}
|
|
36
|
-
async
|
|
38
|
+
async shutdown() {
|
|
37
39
|
await this.producer.disconnect();
|
|
38
40
|
}
|
|
39
|
-
async createConsumer(topic) {
|
|
40
|
-
const consumer = this.kafka.consumer({
|
|
41
|
+
async createConsumer(topic, options) {
|
|
42
|
+
const consumer = this.kafka.consumer({
|
|
43
|
+
groupId: `${this.options.serviceName}Service${this.options.user}ConsumerGroup`,
|
|
44
|
+
sessionTimeout: (options === null || options === void 0 ? void 0 : options.sessionTimeout) || 30000,
|
|
45
|
+
});
|
|
41
46
|
await consumer.connect();
|
|
42
47
|
await consumer.subscribe({ topic, fromBeginning: true });
|
|
43
48
|
return consumer;
|