@restorecommerce/kafka-client 0.3.0 → 0.4.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/CHANGELOG.md +31 -0
- package/LICENSE +1 -1
- package/lib/events/index.js +4 -4
- package/lib/events/provider/kafka/index.d.ts +8 -0
- package/lib/events/provider/kafka/index.js +39 -1
- package/lib/index.js +5 -1
- package/package.json +19 -19
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,37 @@
|
|
|
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
|
+
# [0.4.0](https://github.com/restorecommerce/kafka-client/compare/@restorecommerce/kafka-client@0.3.2...@restorecommerce/kafka-client@0.4.0) (2022-05-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* major upgrade ([a407cb4](https://github.com/restorecommerce/kafka-client/commit/a407cb4ec91c2c36c905d2a1619b9a18708f6c3e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.3.2](https://github.com/restorecommerce/kafka-client/compare/@restorecommerce/kafka-client@0.3.1...@restorecommerce/kafka-client@0.3.2) (2022-04-29)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **kafka-client:** fix to reset consumers on kafkajs crash error KafkaJSNonRetriableError ([2a23174](https://github.com/restorecommerce/kafka-client/commit/2a231741179155c56858ef1e90f32c1dbdbd755a))
|
|
23
|
+
* **kafka-client:** up kafkajs error name ([f20658a](https://github.com/restorecommerce/kafka-client/commit/f20658af9747e3493dda85159dfb8722d12e7676))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## [0.3.1](https://github.com/restorecommerce/kafka-client/compare/@restorecommerce/kafka-client@0.3.0...@restorecommerce/kafka-client@0.3.1) (2022-02-14)
|
|
30
|
+
|
|
31
|
+
**Note:** Version bump only for package @restorecommerce/kafka-client
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
6
37
|
# [0.3.0](https://github.com/restorecommerce/kafka-client/compare/@restorecommerce/kafka-client@0.2.29...@restorecommerce/kafka-client@0.3.0) (2022-02-09)
|
|
7
38
|
|
|
8
39
|
|
package/LICENSE
CHANGED
package/lib/events/index.js
CHANGED
|
@@ -29,8 +29,8 @@ const registerEventProvider = (name, provider) => {
|
|
|
29
29
|
eventProviders[name] = provider;
|
|
30
30
|
};
|
|
31
31
|
exports.registerEventProvider = registerEventProvider;
|
|
32
|
-
exports.registerEventProvider(kafka.Name, kafka.Kafka);
|
|
33
|
-
exports.registerEventProvider(local.Name, local.Local);
|
|
32
|
+
(0, exports.registerEventProvider)(kafka.Name, kafka.Kafka);
|
|
33
|
+
(0, exports.registerEventProvider)(local.Name, local.Local);
|
|
34
34
|
/**
|
|
35
35
|
* Events manages an event provider.
|
|
36
36
|
*/
|
|
@@ -55,10 +55,10 @@ class Events {
|
|
|
55
55
|
// logger
|
|
56
56
|
if (_.isNil(logger)) {
|
|
57
57
|
if (_.isNil(this.config.logger)) {
|
|
58
|
-
this.logger = logger_1.createLogger();
|
|
58
|
+
this.logger = (0, logger_1.createLogger)();
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
this.logger = logger_1.createLogger(loggerCfg);
|
|
61
|
+
this.logger = (0, logger_1.createLogger)(loggerCfg);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
@@ -81,6 +81,14 @@ export declare class Topic {
|
|
|
81
81
|
* with the corresponding offset.
|
|
82
82
|
*/
|
|
83
83
|
$wait(offset: number): Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Reset consumer, unsubscribes all the events on the topic and then
|
|
86
|
+
* subcribes again for same set of events
|
|
87
|
+
*
|
|
88
|
+
* @param {string[]} eventNames list of event names
|
|
89
|
+
* @param {number} offset The offset at which to restart from.
|
|
90
|
+
*/
|
|
91
|
+
$resetConsumer(eventNames: string[], offset: number): Promise<void>;
|
|
84
92
|
/**
|
|
85
93
|
* Force a committed offset reset.
|
|
86
94
|
*
|
|
@@ -183,7 +183,7 @@ class Topic {
|
|
|
183
183
|
return new Promise((() => {
|
|
184
184
|
return (cb) => {
|
|
185
185
|
if (this.currentOffset >= offset) {
|
|
186
|
-
cb();
|
|
186
|
+
cb(null);
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
189
|
this.waitQueue.push({ offset, cb });
|
|
@@ -191,6 +191,36 @@ class Topic {
|
|
|
191
191
|
})());
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Reset consumer, unsubscribes all the events on the topic and then
|
|
196
|
+
* subcribes again for same set of events
|
|
197
|
+
*
|
|
198
|
+
* @param {string[]} eventNames list of event names
|
|
199
|
+
* @param {number} offset The offset at which to restart from.
|
|
200
|
+
*/
|
|
201
|
+
$resetConsumer(eventNames, offset) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
this.provider.logger.info('Event Names for consumer reset', eventNames);
|
|
204
|
+
if (eventNames && eventNames.length > 0) {
|
|
205
|
+
// since the consumer is set to undefined only when there is no more subscription
|
|
206
|
+
// need to unsubcribe all eventNames and then resubcribe at once
|
|
207
|
+
const eventNamesList = _.clone(eventNames);
|
|
208
|
+
// unsubscribe all events on consumer
|
|
209
|
+
for (let eventName of eventNamesList) {
|
|
210
|
+
yield this.$unsubscribe(eventName);
|
|
211
|
+
this.provider.logger.info(`Unsubscribed event ${eventName}`);
|
|
212
|
+
}
|
|
213
|
+
// subscribe all events on consumer
|
|
214
|
+
for (let eventName of eventNamesList) {
|
|
215
|
+
yield this.$subscribe(eventName, offset);
|
|
216
|
+
this.provider.logger.info(`Subscribed event ${eventName}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.provider.logger.warn('Event names empty for consumer reset');
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
194
224
|
/**
|
|
195
225
|
* Force a committed offset reset.
|
|
196
226
|
*
|
|
@@ -358,6 +388,14 @@ class Topic {
|
|
|
358
388
|
this.provider.logger.verbose('Offsets committed successfully');
|
|
359
389
|
}).catch(error => {
|
|
360
390
|
this.provider.logger.warn('Failed to commit offsets, resuming anyway after:', error);
|
|
391
|
+
// Fix for kafkaJS onCrash issue for KafkaJSNonRetriableError, to reset the consumers
|
|
392
|
+
this.provider.logger.warn('Commit error name', { name: error.name });
|
|
393
|
+
this.provider.logger.warn('Commit error message', { message: error.message });
|
|
394
|
+
if ((error.name === 'KafkaJSNonRetriableError' || error.name === 'KafkaJSError') && error.message === 'The coordinator is not aware of this member') {
|
|
395
|
+
this.provider.logger.info('Reset Consumer connection due to KafkaJSNonRetriableError');
|
|
396
|
+
this.$resetConsumer(this.subscribed, this.currentOffset);
|
|
397
|
+
this.provider.logger.info('Consumer connection reset successfully');
|
|
398
|
+
}
|
|
361
399
|
});
|
|
362
400
|
}
|
|
363
401
|
commitCurrentOffsets() {
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restorecommerce/kafka-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Opinionated Kafka Client for Microservices",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
|
-
"author": "
|
|
6
|
+
"author": "n-fuse GmbH",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/restorecommerce/kafka-client.git"
|
|
@@ -17,36 +17,36 @@
|
|
|
17
17
|
],
|
|
18
18
|
"typings": "lib/index.d.ts",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@restorecommerce/logger": "^0.12.
|
|
20
|
+
"@restorecommerce/logger": "^0.12.2",
|
|
21
21
|
"async": "^3.2.0",
|
|
22
22
|
"cls-rtracer": "^2.5.1",
|
|
23
23
|
"events": "^3.3.0",
|
|
24
|
-
"kafkajs": "^
|
|
24
|
+
"kafkajs": "^2.0.0",
|
|
25
25
|
"lodash": "^4.17.21",
|
|
26
26
|
"protobufjs": "^6.11.2",
|
|
27
27
|
"retry": "^0.13.1",
|
|
28
|
-
"winston": "^3.
|
|
28
|
+
"winston": "^3.7.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/async": "^3.2.
|
|
32
|
-
"@types/long": "^4.0.
|
|
33
|
-
"@types/mocha": "^9.
|
|
34
|
-
"@types/node": "^
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
36
|
-
"@typescript-eslint/eslint-plugin-tslint": "^5.
|
|
37
|
-
"@typescript-eslint/parser": "^5.
|
|
38
|
-
"coveralls": "^3.
|
|
31
|
+
"@types/async": "^3.2.13",
|
|
32
|
+
"@types/long": "^4.0.2",
|
|
33
|
+
"@types/mocha": "^9.1.1",
|
|
34
|
+
"@types/node": "^17.0.33",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
36
|
+
"@typescript-eslint/eslint-plugin-tslint": "^5.23.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.23.0",
|
|
38
|
+
"coveralls": "^3.1.1",
|
|
39
39
|
"cross-env": "^7.0.3",
|
|
40
|
-
"eslint": "^8.
|
|
41
|
-
"eslint-plugin-prefer-arrow-functions": "^3.
|
|
42
|
-
"mocha": "^
|
|
40
|
+
"eslint": "^8.15.0",
|
|
41
|
+
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
|
|
42
|
+
"mocha": "^10.0.0",
|
|
43
43
|
"npm-run-all": "^4.1.5",
|
|
44
44
|
"nyc": "^15.1.0",
|
|
45
45
|
"rimraf": "^3.0.0",
|
|
46
46
|
"should": "^13.2.3",
|
|
47
|
-
"ts-node": "^10.
|
|
47
|
+
"ts-node": "^10.7.0",
|
|
48
48
|
"tslint": "^6.1.3",
|
|
49
|
-
"typescript": "^4.
|
|
49
|
+
"typescript": "^4.6.4"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"pretest": "npm run build && node setupTopics.js com.example.test",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">= 12.0.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "ec10625052f498dc6cd83f340b26e18ffdf9a6eb"
|
|
66
66
|
}
|