@onlineapps/mq-client-core 1.0.61 → 1.0.63
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 +3 -2
- package/src/BaseClient.js +22 -20
- package/src/config/defaultConfig.js +5 -15
- package/src/config.js +29 -0
- package/src/defaults.js +17 -0
- package/src/transports/rabbitmqClient.js +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/mq-client-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.63",
|
|
4
4
|
"description": "Core MQ client library for RabbitMQ - shared by infrastructure services and connectors",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"amqplib": "^0.10.3",
|
|
22
22
|
"ajv": "^8.12.0",
|
|
23
23
|
"lodash.merge": "^4.6.2",
|
|
24
|
-
"@onlineapps/
|
|
24
|
+
"@onlineapps/runtime-config": "1.0.2",
|
|
25
|
+
"@onlineapps/infrastructure-tools": "1.0.39"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"jest": "^29.7.0"
|
package/src/BaseClient.js
CHANGED
|
@@ -11,6 +11,7 @@ const merge = require('lodash.merge');
|
|
|
11
11
|
|
|
12
12
|
const configSchema = require('./config/configSchema');
|
|
13
13
|
const defaultConfig = require('./config/defaultConfig');
|
|
14
|
+
const runtimeCfg = require('./config');
|
|
14
15
|
const transportFactory = require('./transports/transportFactory');
|
|
15
16
|
const serializer = require('./utils/serializer');
|
|
16
17
|
const {
|
|
@@ -32,25 +33,20 @@ class BaseClient {
|
|
|
32
33
|
|
|
33
34
|
// Merge user config with defaults
|
|
34
35
|
this._config = merge({}, defaultConfig, config || {});
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this._config.heartbeat =
|
|
50
|
-
this._config.heartbeat ?? Number(process.env.RABBITMQ_HEARTBEAT || 30);
|
|
36
|
+
|
|
37
|
+
// Resolve runtime config (FAIL-FAST for host)
|
|
38
|
+
const resolved = runtimeCfg.resolve({
|
|
39
|
+
host: config?.host,
|
|
40
|
+
heartbeat: config?.heartbeat,
|
|
41
|
+
serviceName: config?.serviceName,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Apply resolved runtime config
|
|
45
|
+
this._config.host = resolved.host;
|
|
46
|
+
this._config.heartbeat = this._config.heartbeat ?? resolved.heartbeat;
|
|
51
47
|
this._config.connectionName =
|
|
52
48
|
this._config.connectionName ||
|
|
53
|
-
`${
|
|
49
|
+
`${resolved.serviceName}:${process.pid}`;
|
|
54
50
|
|
|
55
51
|
// Validate merged config
|
|
56
52
|
const valid = validate(this._config);
|
|
@@ -81,11 +77,17 @@ class BaseClient {
|
|
|
81
77
|
console.log(`[BaseClient] Starting connect() with config:`, JSON.stringify({ type: this._config.type, host: this._config.host }));
|
|
82
78
|
// Merge overrides into existing config
|
|
83
79
|
this._config = merge({}, this._config, options);
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
// Ensure runtime-derived values are applied (options can override explicitly)
|
|
81
|
+
const resolved = runtimeCfg.resolve({
|
|
82
|
+
host: this._config.host,
|
|
83
|
+
heartbeat: this._config.heartbeat,
|
|
84
|
+
serviceName: this._config.serviceName,
|
|
85
|
+
});
|
|
86
|
+
this._config.host = resolved.host;
|
|
87
|
+
this._config.heartbeat = this._config.heartbeat ?? resolved.heartbeat;
|
|
86
88
|
this._config.connectionName =
|
|
87
89
|
this._config.connectionName ||
|
|
88
|
-
`${
|
|
90
|
+
`${resolved.serviceName}:${process.pid}`;
|
|
89
91
|
|
|
90
92
|
try {
|
|
91
93
|
console.log(`[BaseClient] Creating transport...`);
|
|
@@ -7,27 +7,17 @@
|
|
|
7
7
|
* Users can override any of these by passing a custom config object
|
|
8
8
|
* or by supplying overrides to connect().
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Environment variable (checked at runtime, has priority):
|
|
14
|
-
* - RABBITMQ_URL: Full RabbitMQ URL (e.g., amqp://guest:guest@api_services_queuer:5672)
|
|
15
|
-
*
|
|
16
|
-
* Fallback (used only if RABBITMQ_URL is not set):
|
|
17
|
-
* - amqp://guest:guest@api_services_queuer:5672 (docker-compose default)
|
|
18
|
-
*
|
|
19
|
-
* NOTE: host is resolved at runtime in BaseClient constructor, not at module load time.
|
|
10
|
+
* NOTE:
|
|
11
|
+
* - Infrastructure topology (RabbitMQ URL) is NOT defaulted here.
|
|
12
|
+
* - BaseClient resolves host via @onlineapps/runtime-config (fail-fast when missing).
|
|
20
13
|
*/
|
|
21
14
|
|
|
22
15
|
module.exports = {
|
|
23
16
|
// Transport type: currently only 'rabbitmq' is fully supported.
|
|
24
17
|
type: 'rabbitmq',
|
|
25
18
|
|
|
26
|
-
// RabbitMQ connection URI or hostname.
|
|
27
|
-
//
|
|
28
|
-
// and override this if ENV is set. ENV variable name: RABBITMQ_URL
|
|
29
|
-
// Fallback: amqp://guest:guest@api_services_queuer:5672 (docker-compose default)
|
|
30
|
-
host: 'amqp://guest:guest@api_services_queuer:5672',
|
|
19
|
+
// RabbitMQ connection URI or hostname (resolved at runtime; required by schema).
|
|
20
|
+
// Provided via explicit config.host or ENV RABBITMQ_URL.
|
|
31
21
|
|
|
32
22
|
// Default queue name; can be overridden per call to publish/consume.
|
|
33
23
|
// Optional for infrastructure services (they may not need a default queue).
|
package/src/config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime configuration schema for @onlineapps/mq-client-core.
|
|
5
|
+
*
|
|
6
|
+
* Uses @onlineapps/runtime-config for unified priority:
|
|
7
|
+
* 1. Explicit config
|
|
8
|
+
* 2. Environment variable
|
|
9
|
+
* 3. Module-owned defaults (from ./defaults.js)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { createRuntimeConfig } = require('@onlineapps/runtime-config');
|
|
13
|
+
const DEFAULTS = require('./defaults');
|
|
14
|
+
|
|
15
|
+
const runtimeCfg = createRuntimeConfig({
|
|
16
|
+
defaults: DEFAULTS,
|
|
17
|
+
schema: {
|
|
18
|
+
// RabbitMQ topology (FAIL-FAST)
|
|
19
|
+
host: { env: 'RABBITMQ_URL', required: true },
|
|
20
|
+
|
|
21
|
+
// Client behavior
|
|
22
|
+
heartbeat: { env: 'RABBITMQ_HEARTBEAT', defaultKey: 'heartbeatSeconds', type: 'number' },
|
|
23
|
+
serviceName: { env: 'SERVICE_NAME', defaultKey: 'serviceName' },
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
module.exports = runtimeCfg;
|
|
28
|
+
|
|
29
|
+
|
package/src/defaults.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Module-owned defaults for @onlineapps/mq-client-core.
|
|
5
|
+
*
|
|
6
|
+
* Ownership rule:
|
|
7
|
+
* - This module owns defaults for MQ client behavior (heartbeat, connectionName prefix).
|
|
8
|
+
* - Infrastructure topology (RabbitMQ URL) is NOT defaulted; it must be provided via
|
|
9
|
+
* explicit config.host or ENV RABBITMQ_URL (fail-fast).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
heartbeatSeconds: 30,
|
|
14
|
+
serviceName: 'oa-service',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
@@ -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 runtimeCfg = require('../config');
|
|
20
21
|
|
|
21
22
|
// LAZY LOAD: Avoid circular dependency with infrastructure-tools
|
|
22
23
|
// infrastructure-tools imports mq-client-core, so we can't import it at top-level
|
|
@@ -413,7 +414,7 @@ class RabbitMQClient extends EventEmitter {
|
|
|
413
414
|
const connectionName =
|
|
414
415
|
this._config.connectionName ||
|
|
415
416
|
this._config.clientName ||
|
|
416
|
-
`oa-client:${
|
|
417
|
+
`oa-client:${runtimeCfg.get('serviceName')}:${process.pid}`;
|
|
417
418
|
|
|
418
419
|
console.log(`[RabbitMQClient] Attempting to connect to: ${rawTarget}`);
|
|
419
420
|
const connectArgs = typeof rawTarget === 'string'
|
|
@@ -1621,7 +1622,7 @@ class RabbitMQClient extends EventEmitter {
|
|
|
1621
1622
|
const connectionName =
|
|
1622
1623
|
this._config.connectionName ||
|
|
1623
1624
|
this._config.clientName ||
|
|
1624
|
-
`oa-client:${
|
|
1625
|
+
`oa-client:${runtimeCfg.get('serviceName')}:${process.pid}`;
|
|
1625
1626
|
|
|
1626
1627
|
const connectArgs = typeof rawTarget === 'string'
|
|
1627
1628
|
? [rawTarget, { heartbeat, clientProperties: { connection_name: connectionName } }]
|