@restorecommerce/kafka-client 0.3.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
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.3.2](https://github.com/restorecommerce/kafka-client/compare/@restorecommerce/kafka-client@0.3.1...@restorecommerce/kafka-client@0.3.2) (2022-04-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **kafka-client:** fix to reset consumers on kafkajs crash error KafkaJSNonRetriableError ([2a23174](https://github.com/restorecommerce/kafka-client/commit/2a231741179155c56858ef1e90f32c1dbdbd755a))
12
+ * **kafka-client:** up kafkajs error name ([f20658a](https://github.com/restorecommerce/kafka-client/commit/f20658af9747e3493dda85159dfb8722d12e7676))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [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)
7
19
 
8
20
  **Note:** Version bump only for package @restorecommerce/kafka-client
@@ -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
  *
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restorecommerce/kafka-client",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Opinionated Kafka Client for Microservices",
5
5
  "main": "./lib/index.js",
6
6
  "author": "n-fuse GmbH",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">= 12.0.0"
64
64
  },
65
- "gitHead": "e97bbfe2fe8166dfe1cd47ae60bce54347a4f1c9"
65
+ "gitHead": "60cbe93a4777bfc0c7bca921e29370f77e6e584b"
66
66
  }