@onlineapps/mq-client-core 1.0.47 → 1.0.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/mq-client-core",
3
- "version": "1.0.47",
3
+ "version": "1.0.50",
4
4
  "description": "Core MQ client library for RabbitMQ - shared by infrastructure services and connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,7 +22,8 @@
22
22
  "dependencies": {
23
23
  "amqplib": "^0.10.3",
24
24
  "ajv": "^8.12.0",
25
- "lodash.merge": "^4.6.2"
25
+ "lodash.merge": "^4.6.2",
26
+ "@onlineapps/infrastructure-tools": "^1.0.23"
26
27
  },
27
28
  "devDependencies": {
28
29
  "jest": "^29.7.0"
package/src/index.js CHANGED
@@ -8,6 +8,9 @@
8
8
  *
9
9
  * NOTE: Infrastructure orchestration utilities (waitForInfrastructureReady, initInfrastructureQueues)
10
10
  * have been moved to @onlineapps/infrastructure-tools to keep this library focused on core MQ operations.
11
+ *
12
+ * @version 1.0.49
13
+ * @updated 2024-12-08 - Test publish-library.sh workflow
11
14
  */
12
15
 
13
16
  const BaseClient = require('./BaseClient');
@@ -17,6 +17,7 @@ const {
17
17
  const PublishLayer = require('../layers/PublishLayer');
18
18
  const RecoveryWorker = require('../workers/RecoveryWorker');
19
19
  const PublishMonitor = require('../monitoring/PublishMonitor');
20
+ const { createInfraLogger } = require('@onlineapps/infrastructure-tools');
20
21
 
21
22
  class RabbitMQClient extends EventEmitter {
22
23
  /**
@@ -101,6 +102,9 @@ class RabbitMQClient extends EventEmitter {
101
102
  this._criticalHealthShutdownDelay = this._config.criticalHealthShutdownDelay || 60000; // Default: 60s delay before shutdown
102
103
  this._criticalHealthStartTime = null; // Track when critical health started
103
104
 
105
+ // Create structured logger for infrastructure logging
106
+ this._log = createInfraLogger('mq-client-core', 'transport');
107
+
104
108
  // Publish layer (retry + buffer)
105
109
  this._publishLayer = new PublishLayer({
106
110
  client: this,
@@ -1067,13 +1071,26 @@ class RabbitMQClient extends EventEmitter {
1067
1071
  // Track operation for debugging
1068
1072
  this._trackChannelOperation(this._channel, `publish to ${queue}`);
1069
1073
 
1070
- // Log publish attempt for debugging
1071
- console.log(`[RabbitMQClient] [mq-client-core] [PUBLISH] Attempting to publish to queue "${queue}"`);
1072
-
1073
1074
  const exchange = this._config.exchange || '';
1074
1075
  const routingKey = options.routingKey || queue;
1075
1076
  const persistent = options.persistent !== undefined ? options.persistent : this._config.durable;
1076
1077
  const headers = options.headers || {};
1078
+
1079
+ // Structured log: extract workflow_id from headers for traceability
1080
+ const workflowId = headers.workflowId || headers.workflow_id || 'unknown';
1081
+ const msgSize = buffer ? buffer.length : 0;
1082
+ this._log.input(workflowId, 'PUBLISH_START', {
1083
+ handler: 'publish',
1084
+ function: 'RabbitMQClient._publishOnce',
1085
+ input: {
1086
+ queue,
1087
+ size: msgSize,
1088
+ exchange: exchange || '(default)',
1089
+ routing_key: routingKey,
1090
+ persistent
1091
+ }
1092
+ });
1093
+
1077
1094
 
1078
1095
  try {
1079
1096
  // Ensure queue exists if publishing directly to queue and using default exchange
@@ -1221,7 +1238,14 @@ class RabbitMQClient extends EventEmitter {
1221
1238
  reject(err);
1222
1239
  }
1223
1240
  } else {
1224
- console.log(`[RabbitMQClient] [mq-client-core] [PUBLISH] Message confirmed for queue "${queue}"`);
1241
+ // Structured log: publish confirmed
1242
+ const wfId = headers.workflowId || headers.workflow_id || 'unknown';
1243
+ this._log.output(wfId, 'PUBLISH_CONFIRMED', {
1244
+ handler: 'publish',
1245
+ function: 'RabbitMQClient._publishOnce',
1246
+ input: { queue, size: buffer ? buffer.length : 0 },
1247
+ output: { status: 'confirmed', queue }
1248
+ });
1225
1249
  resolve();
1226
1250
  }
1227
1251
  });
@@ -1453,6 +1477,20 @@ class RabbitMQClient extends EventEmitter {
1453
1477
  return; // Consumer cancellation
1454
1478
  }
1455
1479
 
1480
+ // Structured log: message received
1481
+ const msgHeaders = msg.properties?.headers || {};
1482
+ const wfId = msgHeaders.workflowId || msgHeaders.workflow_id || 'unknown';
1483
+ const msgSize = msg.content ? msg.content.length : 0;
1484
+ this._log.input(wfId, 'MSG_RECEIVED', {
1485
+ handler: 'consume',
1486
+ function: 'RabbitMQClient.consume',
1487
+ input: {
1488
+ queue,
1489
+ size: msgSize,
1490
+ consumer_tag: msg.fields?.consumerTag || null
1491
+ }
1492
+ });
1493
+
1456
1494
  // Track in-flight message (increment)
1457
1495
  const tracking = this._prefetchTracking.get(queue);
1458
1496
  if (tracking) {
@@ -1466,6 +1504,14 @@ class RabbitMQClient extends EventEmitter {
1466
1504
  // Acknowledge message after successful processing
1467
1505
  if (!noAck) {
1468
1506
  this._consumerChannel.ack(msg);
1507
+ // Structured log: message acknowledged
1508
+ this._log.output(wfId, 'MSG_ACKED', {
1509
+ handler: 'consume',
1510
+ function: 'RabbitMQClient.consume',
1511
+ input: { queue },
1512
+ output: { status: 'acknowledged', queue }
1513
+ });
1514
+
1469
1515
  // Track ack (decrement in-flight)
1470
1516
  if (tracking) {
1471
1517
  tracking.inFlight = Math.max(0, tracking.inFlight - 1);