wsp-ms-core 1.1.26 → 1.1.27

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/index.js CHANGED
@@ -1244,8 +1244,30 @@ var EventManager = class {
1244
1244
  this._onReconnect = null;
1245
1245
  }
1246
1246
  async execRoute(topic, event) {
1247
- if (this._callbackList[topic]) {
1248
- await this._callbackList[topic](event);
1247
+ console.log("[KafkaManager] execRoute START", {
1248
+ topic
1249
+ });
1250
+ const callback = this._callbackList[topic];
1251
+ if (!callback) {
1252
+ console.log("[KafkaManager] execRoute NO CALLBACK", {
1253
+ topic
1254
+ });
1255
+ return;
1256
+ }
1257
+ const start = Date.now();
1258
+ try {
1259
+ await callback(event);
1260
+ console.log("[KafkaManager] execRoute END", {
1261
+ topic,
1262
+ elapsedMs: Date.now() - start
1263
+ });
1264
+ } catch (e) {
1265
+ console.error("[KafkaManager] execRoute ERROR", {
1266
+ topic,
1267
+ elapsedMs: Date.now() - start,
1268
+ error: e
1269
+ });
1270
+ throw e;
1249
1271
  }
1250
1272
  }
1251
1273
  async execCallback(callback, data) {
@@ -1945,31 +1967,70 @@ var KafkaManager = class extends EventManager {
1945
1967
  autoCommit: false,
1946
1968
  // @ts-ignore
1947
1969
  eachMessage: async ({ topic, partition, message, heartbeat }) => {
1970
+ console.log("[KafkaManager] A - eachMessage START", {
1971
+ topic,
1972
+ partition,
1973
+ offset: message.offset
1974
+ });
1948
1975
  try {
1949
- await this.execCallback(this._onMessage, `[New message detected for ${topic}]: ${message.value?.toString()}`);
1950
- let json;
1951
- let event;
1952
- try {
1953
- json = JSON.parse(String(message.value?.toString()));
1954
- if (!json.data)
1955
- json.data = {};
1956
- event = {
1957
- topic: String(topic),
1958
- producer: String(json.producer),
1959
- tenant: UUID.create(String(json.tenant)),
1960
- message: json.data
1961
- };
1962
- } catch (error) {
1963
- await this.commitMessage(topic, partition, message);
1964
- await heartbeat();
1965
- throw error;
1976
+ console.log("[KafkaManager] B - before execCallback(_onMessage)");
1977
+ await this.execCallback(
1978
+ this._onMessage,
1979
+ `[New message detected for ${topic}]: ${message.value?.toString()}`
1980
+ );
1981
+ console.log("[KafkaManager] C - after execCallback(_onMessage)");
1982
+ console.log("[KafkaManager] D - before JSON.parse");
1983
+ const json = JSON.parse(message.value.toString());
1984
+ console.log("[KafkaManager] E - after JSON.parse");
1985
+ if (!json.data) {
1986
+ json.data = {};
1966
1987
  }
1988
+ console.log("[KafkaManager] F - before EventMessage creation");
1989
+ const event = {
1990
+ topic: String(topic),
1991
+ producer: String(json.producer),
1992
+ tenant: UUID.create(String(json.tenant)),
1993
+ message: json.data
1994
+ };
1995
+ console.log("[KafkaManager] G - EventMessage created");
1996
+ const execRouteStart = Date.now();
1997
+ console.log("[KafkaManager] H - before execRoute", {
1998
+ offset: message.offset
1999
+ });
1967
2000
  await this.execRoute(topic, event);
2001
+ console.log("[KafkaManager] I - after execRoute", {
2002
+ elapsedMs: Date.now() - execRouteStart
2003
+ });
2004
+ const commitStart = Date.now();
2005
+ console.log("[KafkaManager] J - before commitMessage");
1968
2006
  await this.commitMessage(topic, partition, message);
2007
+ console.log("[KafkaManager] K - after commitMessage", {
2008
+ elapsedMs: Date.now() - commitStart
2009
+ });
2010
+ const hbStart = Date.now();
2011
+ console.log("[KafkaManager] L - before heartbeat");
1969
2012
  await heartbeat();
2013
+ console.log("[KafkaManager] M - after heartbeat", {
2014
+ elapsedMs: Date.now() - hbStart
2015
+ });
2016
+ console.log("[KafkaManager] N - eachMessage END");
1970
2017
  } catch (error) {
1971
- await this.execCallback(this._onError, error);
1972
- this.handleKafkaError(error, "consumer.eachMessage", { topic, partition });
2018
+ console.error("[KafkaManager] ERROR inside eachMessage", {
2019
+ topic,
2020
+ partition,
2021
+ offset: message.offset,
2022
+ error
2023
+ });
2024
+ try {
2025
+ await this.execCallback(this._onError, error);
2026
+ } catch (callbackError) {
2027
+ console.error("[KafkaManager] ERROR executing _onError callback", callbackError);
2028
+ }
2029
+ this.handleKafkaError(error, "consumer.eachMessage", {
2030
+ topic,
2031
+ partition,
2032
+ offset: message.offset
2033
+ });
1973
2034
  throw error;
1974
2035
  }
1975
2036
  }