@onlineapps/error-handler-core 1.0.0 → 1.1.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/package.json +1 -2
- package/src/DLQRouter.js +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/error-handler-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Core error handling functionality for OA Drive microservices - classification, retry, circuit breaker, DLQ routing",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,4 +31,3 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
|
package/src/DLQRouter.js
CHANGED
|
@@ -8,6 +8,7 @@ class DLQRouter {
|
|
|
8
8
|
this.enabled = config.dlqEnabled !== false;
|
|
9
9
|
this.mqClient = config.mqClient || null;
|
|
10
10
|
this.dlqNamePattern = config.dlqNamePattern || '{queue}.dlq';
|
|
11
|
+
this.emitMonitoringEvents = config.emitMonitoringEvents !== false;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -51,6 +52,11 @@ class DLQRouter {
|
|
|
51
52
|
await this.mqClient.publish(dlqName, dlqMessage, {
|
|
52
53
|
persistent: true
|
|
53
54
|
});
|
|
55
|
+
|
|
56
|
+
// Emit message_dlq monitoring event
|
|
57
|
+
if (this.emitMonitoringEvents) {
|
|
58
|
+
await this._emitDLQEvent(message, dlqName, originalQueue, error, errorType, context);
|
|
59
|
+
}
|
|
54
60
|
} catch (dlqError) {
|
|
55
61
|
// If DLQ routing fails, log but don't throw
|
|
56
62
|
// (we don't want DLQ failures to break error handling)
|
|
@@ -58,6 +64,46 @@ class DLQRouter {
|
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Emit message_dlq event to monitoring
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async _emitDLQEvent(message, dlqName, originalQueue, error, errorType, context) {
|
|
72
|
+
if (!this.mqClient) return;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const workflowId = message.workflow_id || context.workflow_id || 'unknown';
|
|
76
|
+
|
|
77
|
+
await this.mqClient.publish('monitoring.workflow', {
|
|
78
|
+
event_type: 'message_dlq',
|
|
79
|
+
workflow_id: workflowId,
|
|
80
|
+
service_name: 'dlq-router',
|
|
81
|
+
step_id: 'dlq-entry',
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
context: {
|
|
84
|
+
_dlq: {
|
|
85
|
+
queue: dlqName,
|
|
86
|
+
originalQueue: originalQueue,
|
|
87
|
+
reason: error.message,
|
|
88
|
+
errorType: errorType,
|
|
89
|
+
retryCount: message.retryCount || context.retryCount || 0,
|
|
90
|
+
routedAt: new Date().toISOString()
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
metadata: {
|
|
94
|
+
dlq_queue: dlqName,
|
|
95
|
+
original_queue: originalQueue,
|
|
96
|
+
error_type: errorType
|
|
97
|
+
}
|
|
98
|
+
}, { persistent: true });
|
|
99
|
+
|
|
100
|
+
console.log(`[DLQRouter] ✓ Emitted message_dlq event for ${workflowId}`);
|
|
101
|
+
} catch (emitError) {
|
|
102
|
+
// Silent fail - don't break DLQ routing
|
|
103
|
+
console.warn(`[DLQRouter] Failed to emit monitoring event:`, emitError.message);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
61
107
|
/**
|
|
62
108
|
* Generate DLQ name from original queue name
|
|
63
109
|
* @private
|