kafka-ts 0.0.14 → 0.0.16

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.
@@ -122,6 +122,7 @@ class Connection {
122
122
  }
123
123
  catch (error) {
124
124
  if (error instanceof error_1.KafkaTSApiError) {
125
+ error.apiName = apiName;
125
126
  error.request = body;
126
127
  }
127
128
  throw error;
@@ -42,6 +42,7 @@ export declare class Consumer extends EventEmitter<{
42
42
  start(): Promise<void>;
43
43
  close(force?: boolean): Promise<void>;
44
44
  private startFetchManager;
45
+ private waitForReassignment;
45
46
  private process;
46
47
  private fetch;
47
48
  }
@@ -131,15 +131,13 @@ class Consumer extends events_1.default {
131
131
  });
132
132
  await this.fetchManager.start();
133
133
  if (!nodeAssignments.length) {
134
- logger_1.log.debug('No partitions assigned. Waiting for reassignment...', { groupId });
135
- await (0, delay_1.delay)(this.options.maxWaitMs);
136
- this.consumerGroup?.handleLastHeartbeat();
134
+ await this.waitForReassignment();
137
135
  }
138
136
  }
139
137
  catch (error) {
140
138
  await this.fetchManager?.stop();
141
139
  if (error.errorCode === api_1.API_ERROR.REBALANCE_IN_PROGRESS) {
142
- logger_1.log.debug('Rebalance in progress...');
140
+ logger_1.log.debug('Rebalance in progress...', { apiName: error.apiName });
143
141
  continue;
144
142
  }
145
143
  if (error.errorCode === api_1.API_ERROR.FENCED_INSTANCE_ID) {
@@ -162,6 +160,14 @@ class Consumer extends events_1.default {
162
160
  }
163
161
  this.stopHook?.();
164
162
  }
163
+ async waitForReassignment() {
164
+ const { groupId } = this.options;
165
+ logger_1.log.debug('No partitions assigned. Waiting for reassignment...', { groupId });
166
+ while (!this.stopHook) {
167
+ await (0, delay_1.delay)(1000);
168
+ this.consumerGroup?.handleLastHeartbeat();
169
+ }
170
+ }
165
171
  async process(messages) {
166
172
  const { options } = this;
167
173
  const { retrier } = options;
@@ -5,6 +5,7 @@ export declare class KafkaTSApiError<T = any> extends KafkaTSError {
5
5
  errorCode: number;
6
6
  errorMessage: string | null;
7
7
  response: T;
8
+ apiName: string | undefined;
8
9
  request: unknown | undefined;
9
10
  constructor(errorCode: number, errorMessage: string | null, response: T);
10
11
  }
@@ -13,6 +13,7 @@ class KafkaTSApiError extends KafkaTSError {
13
13
  errorCode;
14
14
  errorMessage;
15
15
  response;
16
+ apiName;
16
17
  request;
17
18
  constructor(errorCode, errorMessage, response) {
18
19
  const [errorName] = Object.entries(api_1.API_ERROR).find(([, value]) => value === errorCode) ?? ['UNKNOWN'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kafka-ts",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "main": "dist/index.js",
5
5
  "author": "Priit Käärd",
6
6
  "license": "MIT",