@midwayjs/kafka 3.4.11 → 3.5.0
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/framework.d.ts +1 -1
- package/dist/framework.js +21 -26
- package/dist/interface.d.ts +8 -0
- package/package.json +4 -4
package/dist/framework.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseFramework } from '@midwayjs/core';
|
|
|
2
2
|
import { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
export declare class MidwayKafkaFramework extends BaseFramework<any, any, any> {
|
|
4
4
|
configure(): any;
|
|
5
|
-
applicationInitialize(
|
|
5
|
+
applicationInitialize(): Promise<void>;
|
|
6
6
|
run(): Promise<void>;
|
|
7
7
|
private loadSubscriber;
|
|
8
8
|
getFrameworkName(): string;
|
package/dist/framework.js
CHANGED
|
@@ -14,7 +14,7 @@ let MidwayKafkaFramework = class MidwayKafkaFramework extends core_1.BaseFramewo
|
|
|
14
14
|
configure() {
|
|
15
15
|
return this.configService.getConfiguration('kafka');
|
|
16
16
|
}
|
|
17
|
-
async applicationInitialize(
|
|
17
|
+
async applicationInitialize() {
|
|
18
18
|
// Create a connection manager
|
|
19
19
|
this.app = new kafka_1.KafkaConsumerServer({
|
|
20
20
|
logger: this.logger,
|
|
@@ -39,33 +39,28 @@ let MidwayKafkaFramework = class MidwayKafkaFramework extends core_1.BaseFramewo
|
|
|
39
39
|
});
|
|
40
40
|
for (const module of subscriberModules) {
|
|
41
41
|
const data = (0, decorator_1.listPropertyDataFromClass)(decorator_1.MS_CONSUMER_KEY, module);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
Object.keys(e2[0].subscription).length > 0) {
|
|
54
|
-
subscription = e2[0].subscription;
|
|
55
|
-
}
|
|
56
|
-
if (typeof e2[0].runConfig !== 'undefined' &&
|
|
57
|
-
Object.keys(e2[0].runConfig).length > 0) {
|
|
58
|
-
runConfig = e2[0].runConfig;
|
|
59
|
-
}
|
|
42
|
+
const topicTitles = [...new Set(data.map(e => e[0].topic))];
|
|
43
|
+
const midwayConsumerConfigs = topicTitles.map(e => {
|
|
44
|
+
const midwayConsumerConfig = {
|
|
45
|
+
topic: e,
|
|
46
|
+
subscription: {},
|
|
47
|
+
runConfig: {},
|
|
48
|
+
};
|
|
49
|
+
const comsumerParams = data
|
|
50
|
+
.map(value => {
|
|
51
|
+
if (value[0].topic === midwayConsumerConfig.topic) {
|
|
52
|
+
return Object.assign(midwayConsumerConfig, value[0]);
|
|
60
53
|
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
})
|
|
55
|
+
.filter(e => e && true);
|
|
56
|
+
if (comsumerParams && Object.keys(comsumerParams[0]).length > 0) {
|
|
57
|
+
return comsumerParams[0];
|
|
58
|
+
}
|
|
59
|
+
return midwayConsumerConfig;
|
|
65
60
|
});
|
|
66
|
-
|
|
61
|
+
midwayConsumerConfigs.forEach(async (e) => {
|
|
67
62
|
await this.app.connection.subscribe(Object.assign({
|
|
68
|
-
topics:
|
|
63
|
+
topics: topicTitles,
|
|
69
64
|
}, e.subscription));
|
|
70
65
|
await this.app.connection.run(Object.assign(e.runConfig, {
|
|
71
66
|
eachMessage: async ({ topic, partition, message }) => {
|
|
@@ -90,7 +85,7 @@ let MidwayKafkaFramework = class MidwayKafkaFramework extends core_1.BaseFramewo
|
|
|
90
85
|
};
|
|
91
86
|
this.app.createAnonymousContext(ctx);
|
|
92
87
|
const ins = await ctx.requestContext.getAsync(module);
|
|
93
|
-
const fn = await this.applyMiddleware(async (
|
|
88
|
+
const fn = await this.applyMiddleware(async () => {
|
|
94
89
|
return await ins[propertyKey].call(ins, message);
|
|
95
90
|
});
|
|
96
91
|
try {
|
package/dist/interface.d.ts
CHANGED
|
@@ -16,4 +16,12 @@ export interface Context extends IMidwayKafkaContext {
|
|
|
16
16
|
}
|
|
17
17
|
export declare type NextFunction = BaseNextFunction;
|
|
18
18
|
export declare type DefaultConfig = string | Kafka;
|
|
19
|
+
/**
|
|
20
|
+
* 客户端的相关配置,在midwayjs的自定义配置项
|
|
21
|
+
*/
|
|
22
|
+
export interface IMidwayConsumerConfig {
|
|
23
|
+
topic: string;
|
|
24
|
+
subscription: any;
|
|
25
|
+
runConfig: any;
|
|
26
|
+
}
|
|
19
27
|
//# sourceMappingURL=interface.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/kafka",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Midway Framework for kafka",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/midwayjs/midway#readme",
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@midwayjs/core": "^3.
|
|
36
|
+
"@midwayjs/core": "^3.5.0",
|
|
37
37
|
"@midwayjs/decorator": "^3.4.11",
|
|
38
38
|
"@midwayjs/logger": "^2.15.0",
|
|
39
|
-
"@midwayjs/mock": "^3.
|
|
39
|
+
"@midwayjs/mock": "^3.5.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"kafkajs": "2.1.0"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=12"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4200e30d1af97a7817c36899c4ffc41a7d97c06d"
|
|
48
48
|
}
|