@midwayjs/kafka 3.4.10 → 3.4.11

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.js CHANGED
@@ -39,49 +39,78 @@ 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
- for (const methodBindListeners of data) {
43
- for (const listenerOptions of methodBindListeners) {
44
- await this.app.connection.subscribe({
45
- topic: listenerOptions.topic,
46
- // fromBeginning: true,
47
- });
48
- await this.app.connection.run({
49
- autoCommit: false,
50
- eachMessage: async ({ topic, partition, message }) => {
51
- const ctx = {
52
- topic: topic,
53
- partition: partition,
54
- message: message,
55
- commitOffsets: (offset) => {
56
- return this.app.connection.commitOffsets([
57
- {
58
- topic: topic,
59
- partition: partition,
60
- offset,
42
+ const topics = [...new Set(data.map(e => e[0].topic))];
43
+ let tempTopics = [];
44
+ topics.forEach(e => {
45
+ tempTopics.push({ topic: e });
46
+ });
47
+ tempTopics = tempTopics.map(e => {
48
+ let subscription = {};
49
+ let runConfig = {};
50
+ data.forEach(e2 => {
51
+ if (e2[0].topic === e.topic) {
52
+ if (typeof e2[0].subscription !== 'undefined' &&
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
+ }
60
+ }
61
+ });
62
+ e.subscription = subscription;
63
+ e.runConfig = runConfig;
64
+ return e;
65
+ });
66
+ tempTopics.forEach(async (e) => {
67
+ await this.app.connection.subscribe(Object.assign({
68
+ topics: topics,
69
+ }, e.subscription));
70
+ await this.app.connection.run(Object.assign(e.runConfig, {
71
+ eachMessage: async ({ topic, partition, message }) => {
72
+ let propertyKey;
73
+ for (const methodBindListeners of data) {
74
+ for (const listenerOptions of methodBindListeners) {
75
+ if (topic === listenerOptions.topic) {
76
+ propertyKey = listenerOptions.propertyKey;
77
+ const ctx = {
78
+ topic: topic,
79
+ partition: partition,
80
+ message: message,
81
+ commitOffsets: (offset) => {
82
+ return this.app.connection.commitOffsets([
83
+ {
84
+ topic: topic,
85
+ partition: partition,
86
+ offset,
87
+ },
88
+ ]);
61
89
  },
62
- ]);
63
- },
64
- };
65
- this.app.createAnonymousContext(ctx);
66
- const ins = await ctx.requestContext.getAsync(module);
67
- const fn = await this.applyMiddleware(async (ctx) => {
68
- return await ins[listenerOptions.propertyKey].call(ins, message);
69
- });
70
- try {
71
- const result = await fn(ctx);
72
- // 返回为undefined,下面永远不会执行
73
- if (result) {
74
- const res = await this.app.connection.commitOffsets(message.offset);
75
- return res;
90
+ };
91
+ this.app.createAnonymousContext(ctx);
92
+ const ins = await ctx.requestContext.getAsync(module);
93
+ const fn = await this.applyMiddleware(async (ctx) => {
94
+ return await ins[propertyKey].call(ins, message);
95
+ });
96
+ try {
97
+ const result = await fn(ctx);
98
+ // 返回为undefined,下面永远不会执行
99
+ if (result) {
100
+ const res = await this.app.connection.commitOffsets(message.offset);
101
+ return res;
102
+ }
103
+ }
104
+ catch (error) {
105
+ // 记录偏移量提交的异常情况
106
+ this.logger.error(error);
107
+ }
76
108
  }
77
109
  }
78
- catch (error) {
79
- this.logger.error(error);
80
- }
81
- },
82
- });
83
- }
84
- }
110
+ }
111
+ },
112
+ }));
113
+ });
85
114
  }
86
115
  }
87
116
  getFrameworkName() {
package/dist/kafka.d.ts CHANGED
@@ -5,7 +5,7 @@ import { IKafkaApplication } from './interface';
5
5
  import { EventEmitter } from 'stream';
6
6
  export declare class KafkaConsumerServer extends EventEmitter implements IKafkaApplication {
7
7
  protected loggers: ILogger;
8
- protected connection: Consumer;
8
+ connection: Consumer;
9
9
  constructor(options?: any);
10
10
  bindError(): void;
11
11
  connect(options: KafkaConfig, consumerOptions: ConsumerConfig): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/kafka",
3
- "version": "3.4.10",
3
+ "version": "3.4.11",
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.4.10",
37
- "@midwayjs/decorator": "^3.4.4",
36
+ "@midwayjs/core": "^3.4.11",
37
+ "@midwayjs/decorator": "^3.4.11",
38
38
  "@midwayjs/logger": "^2.15.0",
39
- "@midwayjs/mock": "^3.4.10"
39
+ "@midwayjs/mock": "^3.4.11"
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": "aeb117633ecbc3299002b220f436dc3b5450d361"
47
+ "gitHead": "942dd076d60f27d6004640fa6dd9a9724efc559d"
48
48
  }