@rsdk/kafka.producer.direct 5.3.0 → 5.4.0-next.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/CHANGELOG.md +8 -0
- package/dist/direct-events.factory.js +2 -1
- package/dist/direct-events.factory.js.map +1 -1
- package/dist/direct-outbox.module-generator.js +17 -6
- package/dist/direct-outbox.module-generator.js.map +1 -1
- package/dist/producers/batch.producer.d.ts +4 -4
- package/dist/producers/batch.producer.js +4 -4
- package/dist/producers/batch.producer.js.map +1 -1
- package/dist/producers/single.producer.d.ts +1 -1
- package/dist/producers/single.producer.js +2 -2
- package/dist/producers/single.producer.js.map +1 -1
- package/package.json +2 -2
- package/src/direct-events.factory.ts +3 -1
- package/src/direct-outbox.module-generator.ts +23 -5
- package/src/producers/batch.producer.ts +7 -4
- package/src/producers/single.producer.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.4.0-next.1](https://github.com/R-Vision/rsdk/compare/v5.4.0-next.0...v5.4.0-next.1) (2024-11-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rsdk/kafka.producer.direct
|
|
9
|
+
|
|
10
|
+
## [5.4.0-next.0](https://github.com/R-Vision/rsdk/compare/v5.3.0...v5.4.0-next.0) (2024-11-08)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @rsdk/kafka.producer.direct
|
|
13
|
+
|
|
6
14
|
## [5.3.0](https://github.com/R-Vision/rsdk/compare/v5.3.0-next.4...v5.3.0) (2024-11-08)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @rsdk/kafka.producer.direct
|
|
@@ -5,7 +5,7 @@ const kafka_producer_1 = require("@rsdk/kafka.producer");
|
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
class EventsFactoryDirect extends kafka_producer_1.EventsFactory {
|
|
7
7
|
create(payload, options) {
|
|
8
|
-
|
|
8
|
+
const event = {
|
|
9
9
|
headers: {
|
|
10
10
|
id: (0, node_crypto_1.randomUUID)(),
|
|
11
11
|
type: this.eventType.$type,
|
|
@@ -17,6 +17,7 @@ class EventsFactoryDirect extends kafka_producer_1.EventsFactory {
|
|
|
17
17
|
}),
|
|
18
18
|
value: this.serializePayload(payload),
|
|
19
19
|
};
|
|
20
|
+
return this.useMiddleware(event);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
exports.EventsFactoryDirect = EventsFactoryDirect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct-events.factory.js","sourceRoot":"","sources":["../src/direct-events.factory.ts"],"names":[],"mappings":";;;AAEA,yDAAqD;AAErD,6CAAyC;AAEzC,MAAa,mBAAyC,SAAQ,8BAG7D;IACC,MAAM,CACJ,OAAU,EACV,OAAwB;QAExB,
|
|
1
|
+
{"version":3,"file":"direct-events.factory.js","sourceRoot":"","sources":["../src/direct-events.factory.ts"],"names":[],"mappings":";;;AAEA,yDAAqD;AAErD,6CAAyC;AAEzC,MAAa,mBAAyC,SAAQ,8BAG7D;IACC,MAAM,CACJ,OAAU,EACV,OAAwB;QAExB,MAAM,KAAK,GAAY;YACrB,OAAO,EAAE;gBACP,EAAE,EAAE,IAAA,wBAAU,GAAE;gBAChB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK;gBAC1B,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;aACpE;YACD,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;gBAClB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;gBAC3C,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC;aAChD,CAAC;YACF,KAAK,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;SACtC,CAAC;QAEF,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;CACF;AAvBD,kDAuBC"}
|
|
@@ -19,10 +19,17 @@ class DirectOutboxModuleGenerator {
|
|
|
19
19
|
static createModule(eventType) {
|
|
20
20
|
const providers = [
|
|
21
21
|
{
|
|
22
|
-
inject: [
|
|
22
|
+
inject: [
|
|
23
|
+
kafka_common_1.KAFKA_PRODUCER_INJECTION_TOKEN,
|
|
24
|
+
kafka_producer_1.ProducerConfig,
|
|
25
|
+
kafka_common_1.KAFKA_PRODUCER_OPTIONS,
|
|
26
|
+
],
|
|
23
27
|
provide: (0, constants_1.createDirectProducerToken)(eventType),
|
|
24
|
-
useFactory: (client, config) => {
|
|
25
|
-
return new single_producer_1.DirectProducer(client, eventType,
|
|
28
|
+
useFactory: (client, config, options) => {
|
|
29
|
+
return new single_producer_1.DirectProducer(client, eventType, {
|
|
30
|
+
...config,
|
|
31
|
+
...options,
|
|
32
|
+
});
|
|
26
33
|
},
|
|
27
34
|
},
|
|
28
35
|
];
|
|
@@ -51,9 +58,13 @@ class DirectOutboxModuleGenerator {
|
|
|
51
58
|
const providers = [
|
|
52
59
|
{
|
|
53
60
|
provide: (0, constants_1.createDirectBatchProducerToken)(eventTypes),
|
|
54
|
-
inject: [
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
inject: [
|
|
62
|
+
kafka_common_1.KAFKA_PRODUCER_INJECTION_TOKEN,
|
|
63
|
+
kafka_producer_1.ProducerConfig,
|
|
64
|
+
kafka_common_1.KAFKA_PRODUCER_OPTIONS,
|
|
65
|
+
],
|
|
66
|
+
useFactory(client, config, options) {
|
|
67
|
+
return new batch_producer_1.DirectBatchProducer(client, { ...config, ...options });
|
|
57
68
|
},
|
|
58
69
|
},
|
|
59
70
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct-outbox.module-generator.js","sourceRoot":"","sources":["../src/direct-outbox.module-generator.ts"],"names":[],"mappings":";;;;;;AACA,6DAAyD;AACzD,qCAAkD;
|
|
1
|
+
{"version":3,"file":"direct-outbox.module-generator.js","sourceRoot":"","sources":["../src/direct-outbox.module-generator.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EventType } from '@rsdk/kafka.common';
|
|
2
|
-
import type { BatchProducerItem
|
|
3
|
-
import type { RawKafkaBatchProducer } from '@rsdk/kafka.producer/dist/interfaces';
|
|
2
|
+
import type { BatchProducerItem } from '@rsdk/kafka.producer';
|
|
3
|
+
import type { ProducerOptions, RawKafkaBatchProducer } from '@rsdk/kafka.producer/dist/interfaces';
|
|
4
4
|
import type { Producer } from 'kafkajs';
|
|
5
5
|
/**
|
|
6
6
|
* Producer, способный отправлять несколько ивентов за раз,
|
|
@@ -8,7 +8,7 @@ import type { Producer } from 'kafkajs';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class DirectBatchProducer implements RawKafkaBatchProducer {
|
|
10
10
|
private readonly client;
|
|
11
|
-
private readonly
|
|
12
|
-
constructor(client: Producer,
|
|
11
|
+
private readonly options;
|
|
12
|
+
constructor(client: Producer, options: ProducerOptions);
|
|
13
13
|
publish<E extends EventType>(items: BatchProducerItem<E>[]): Promise<void>;
|
|
14
14
|
}
|
|
@@ -9,10 +9,10 @@ const direct_events_factory_1 = require("../direct-events.factory");
|
|
|
9
9
|
*/
|
|
10
10
|
class DirectBatchProducer {
|
|
11
11
|
client;
|
|
12
|
-
|
|
13
|
-
constructor(client,
|
|
12
|
+
options;
|
|
13
|
+
constructor(client, options) {
|
|
14
14
|
this.client = client;
|
|
15
|
-
this.
|
|
15
|
+
this.options = options;
|
|
16
16
|
}
|
|
17
17
|
async publish(items) {
|
|
18
18
|
const aggregateByTopic = items.reduce((acc, item) => {
|
|
@@ -24,7 +24,7 @@ class DirectBatchProducer {
|
|
|
24
24
|
}, new Map());
|
|
25
25
|
for (const [topic, items] of aggregateByTopic) {
|
|
26
26
|
const messages = items.map(({ payload, options, eventType }) => {
|
|
27
|
-
const factory = new direct_events_factory_1.EventsFactoryDirect(eventType, this.
|
|
27
|
+
const factory = new direct_events_factory_1.EventsFactoryDirect(eventType, this.options);
|
|
28
28
|
return factory.create(payload, options);
|
|
29
29
|
});
|
|
30
30
|
// TODO: А точно надо в каждый топик последовательно слать это?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.producer.js","sourceRoot":"","sources":["../../src/producers/batch.producer.ts"],"names":[],"mappings":";;;AACA,qDAAoE;
|
|
1
|
+
{"version":3,"file":"batch.producer.js","sourceRoot":"","sources":["../../src/producers/batch.producer.ts"],"names":[],"mappings":";;;AACA,qDAAoE;AAQpE,oEAA+D;AAE/D;;;GAGG;AACH,MAAa,mBAAmB;IAEX;IACA;IAFnB,YACmB,MAAgB,EAChB,OAAwB;QADxB,WAAM,GAAN,MAAM,CAAU;QAChB,YAAO,GAAP,OAAO,CAAiB;IACxC,CAAC;IAEJ,KAAK,CAAC,OAAO,CACX,KAA6B;QAE7B,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YAClD,MAAM,KAAK,GAAG,IAAA,2BAAY,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAEnC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACtB,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,IAAI,GAAG,EAAoC,CAAC,CAAC;QAEhD,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,gBAAgB,EAAE,CAAC;YAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE;gBAC7D,MAAM,OAAO,GAAG,IAAI,2CAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEjE,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;YAEH,+DAA+D;YAE/D,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YACxD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAA,+BAAgB,EAAC,KAAK,EAAE,KAAK,EAAE;oBAC7B,KAAK;oBACL,gBAAgB;oBAChB,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAtCD,kDAsCC"}
|
|
@@ -8,6 +8,6 @@ export declare class DirectProducer<T extends EventType> implements KafkaProduce
|
|
|
8
8
|
private readonly client;
|
|
9
9
|
private readonly factory;
|
|
10
10
|
private readonly topic;
|
|
11
|
-
constructor(client: Producer, eventType: T,
|
|
11
|
+
constructor(client: Producer, eventType: T, options: ProducerOptions);
|
|
12
12
|
publish<P extends EventPayload<T>>(payload: P, options?: PublishOptions): Promise<void>;
|
|
13
13
|
}
|
|
@@ -10,9 +10,9 @@ class DirectProducer {
|
|
|
10
10
|
client;
|
|
11
11
|
factory;
|
|
12
12
|
topic;
|
|
13
|
-
constructor(client, eventType,
|
|
13
|
+
constructor(client, eventType, options) {
|
|
14
14
|
this.client = client;
|
|
15
|
-
this.factory = new direct_events_factory_1.EventsFactoryDirect(eventType,
|
|
15
|
+
this.factory = new direct_events_factory_1.EventsFactoryDirect(eventType, options);
|
|
16
16
|
this.topic = (0, kafka_common_1.getTopicName)(eventType);
|
|
17
17
|
}
|
|
18
18
|
async publish(payload, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single.producer.js","sourceRoot":"","sources":["../../src/producers/single.producer.ts"],"names":[],"mappings":";;;AACA,qDAAoE;AAQpE,oEAA+D;AAE/D;;GAEG;AACH,MAAa,cAAc;IACR,MAAM,CAAW;IACjB,OAAO,CAAyB;IAChC,KAAK,CAAS;IAE/B,YAAY,MAAgB,EAAE,SAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"single.producer.js","sourceRoot":"","sources":["../../src/producers/single.producer.ts"],"names":[],"mappings":";;;AACA,qDAAoE;AAQpE,oEAA+D;AAE/D;;GAEG;AACH,MAAa,cAAc;IACR,MAAM,CAAW;IACjB,OAAO,CAAyB;IAChC,KAAK,CAAS;IAE/B,YAAY,MAAgB,EAAE,SAAY,EAAE,OAAwB;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,2CAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,GAAG,IAAA,2BAAY,EAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,OAAO,CACX,OAAU,EACV,OAAwB;QAExB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAEzD,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAA,+BAAgB,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF;AAvBD,wCAuBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/kafka.producer.direct",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0-next.1",
|
|
4
4
|
"description": "Publishing messages directly to kafka",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"lodash": "^4.17.21"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "de7a6d46a28e5d5e90eb9ba36cea1ee48891505a"
|
|
33
33
|
}
|
|
@@ -12,7 +12,7 @@ export class EventsFactoryDirect<E extends EventType> extends EventsFactory<
|
|
|
12
12
|
payload: P,
|
|
13
13
|
options?: PublishOptions,
|
|
14
14
|
): Message {
|
|
15
|
-
|
|
15
|
+
const event: Message = {
|
|
16
16
|
headers: {
|
|
17
17
|
id: randomUUID(),
|
|
18
18
|
type: this.eventType.$type,
|
|
@@ -24,5 +24,7 @@ export class EventsFactoryDirect<E extends EventType> extends EventsFactory<
|
|
|
24
24
|
}),
|
|
25
25
|
value: this.serializePayload(payload),
|
|
26
26
|
};
|
|
27
|
+
|
|
28
|
+
return this.useMiddleware(event);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { DynamicModule, FactoryProvider } from '@nestjs/common';
|
|
2
2
|
import { AutodocMetadata } from '@rsdk/autodoc.protocol';
|
|
3
3
|
import { PlatformConfigModule } from '@rsdk/core';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
EventType,
|
|
6
|
+
KafkaProducerOptions,
|
|
7
|
+
KafkaTopicMetadata,
|
|
8
|
+
} from '@rsdk/kafka.common';
|
|
5
9
|
import {
|
|
6
10
|
getTopicName,
|
|
7
11
|
KAFKA_PRODUCER_INJECTION_TOKEN,
|
|
12
|
+
KAFKA_PRODUCER_OPTIONS,
|
|
8
13
|
KAFKA_TOPIC_RSDK_METADATA_SCOPE,
|
|
9
14
|
KafkaClientModule,
|
|
10
15
|
TopicType,
|
|
@@ -28,13 +33,21 @@ export class DirectOutboxModuleGenerator {
|
|
|
28
33
|
static createModule(eventType: EventType): DynamicModule {
|
|
29
34
|
const providers: FactoryProvider[] = [
|
|
30
35
|
{
|
|
31
|
-
inject: [
|
|
36
|
+
inject: [
|
|
37
|
+
KAFKA_PRODUCER_INJECTION_TOKEN,
|
|
38
|
+
ProducerConfig,
|
|
39
|
+
KAFKA_PRODUCER_OPTIONS,
|
|
40
|
+
],
|
|
32
41
|
provide: createDirectProducerToken(eventType),
|
|
33
42
|
useFactory: (
|
|
34
43
|
client: Producer,
|
|
35
44
|
config: ProducerConfig,
|
|
45
|
+
options: KafkaProducerOptions,
|
|
36
46
|
): DirectProducer<EventType> => {
|
|
37
|
-
return new DirectProducer(client, eventType,
|
|
47
|
+
return new DirectProducer(client, eventType, {
|
|
48
|
+
...config,
|
|
49
|
+
...options,
|
|
50
|
+
});
|
|
38
51
|
},
|
|
39
52
|
},
|
|
40
53
|
];
|
|
@@ -76,12 +89,17 @@ export class DirectOutboxModuleGenerator {
|
|
|
76
89
|
const providers: FactoryProvider[] = [
|
|
77
90
|
{
|
|
78
91
|
provide: createDirectBatchProducerToken(eventTypes),
|
|
79
|
-
inject: [
|
|
92
|
+
inject: [
|
|
93
|
+
KAFKA_PRODUCER_INJECTION_TOKEN,
|
|
94
|
+
ProducerConfig,
|
|
95
|
+
KAFKA_PRODUCER_OPTIONS,
|
|
96
|
+
],
|
|
80
97
|
useFactory(
|
|
81
98
|
client: Producer,
|
|
82
99
|
config: ProducerConfig,
|
|
100
|
+
options: KafkaProducerOptions,
|
|
83
101
|
): KafkaBatchProducer<typeof eventTypes> {
|
|
84
|
-
return new DirectBatchProducer(client, config);
|
|
102
|
+
return new DirectBatchProducer(client, { ...config, ...options });
|
|
85
103
|
},
|
|
86
104
|
},
|
|
87
105
|
];
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { EventType } from '@rsdk/kafka.common';
|
|
2
2
|
import { getTopicName, handleKafkaError } from '@rsdk/kafka.common';
|
|
3
|
-
import type { BatchProducerItem
|
|
4
|
-
import type {
|
|
3
|
+
import type { BatchProducerItem } from '@rsdk/kafka.producer';
|
|
4
|
+
import type {
|
|
5
|
+
ProducerOptions,
|
|
6
|
+
RawKafkaBatchProducer,
|
|
7
|
+
} from '@rsdk/kafka.producer/dist/interfaces';
|
|
5
8
|
import type { Producer } from 'kafkajs';
|
|
6
9
|
|
|
7
10
|
import { EventsFactoryDirect } from '../direct-events.factory';
|
|
@@ -13,7 +16,7 @@ import { EventsFactoryDirect } from '../direct-events.factory';
|
|
|
13
16
|
export class DirectBatchProducer implements RawKafkaBatchProducer {
|
|
14
17
|
constructor(
|
|
15
18
|
private readonly client: Producer,
|
|
16
|
-
private readonly
|
|
19
|
+
private readonly options: ProducerOptions,
|
|
17
20
|
) {}
|
|
18
21
|
|
|
19
22
|
async publish<E extends EventType>(
|
|
@@ -30,7 +33,7 @@ export class DirectBatchProducer implements RawKafkaBatchProducer {
|
|
|
30
33
|
|
|
31
34
|
for (const [topic, items] of aggregateByTopic) {
|
|
32
35
|
const messages = items.map(({ payload, options, eventType }) => {
|
|
33
|
-
const factory = new EventsFactoryDirect(eventType, this.
|
|
36
|
+
const factory = new EventsFactoryDirect(eventType, this.options);
|
|
34
37
|
|
|
35
38
|
return factory.create(payload, options);
|
|
36
39
|
});
|
|
@@ -17,9 +17,9 @@ export class DirectProducer<T extends EventType> implements KafkaProducer<T> {
|
|
|
17
17
|
private readonly factory: EventsFactoryDirect<T>;
|
|
18
18
|
private readonly topic: string;
|
|
19
19
|
|
|
20
|
-
constructor(client: Producer, eventType: T,
|
|
20
|
+
constructor(client: Producer, eventType: T, options: ProducerOptions) {
|
|
21
21
|
this.client = client;
|
|
22
|
-
this.factory = new EventsFactoryDirect(eventType,
|
|
22
|
+
this.factory = new EventsFactoryDirect(eventType, options);
|
|
23
23
|
this.topic = getTopicName(eventType);
|
|
24
24
|
}
|
|
25
25
|
|