@ti-engine/core 1.1.5 → 1.1.9
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/CHANGELOG.md +39 -0
- package/README.md +45 -11
- package/bin/start-instance.js +40 -16
- package/components/auditing.js +3 -3
- package/components/exchange/default/default-message-receiver.js +6 -2
- package/components/exchange/default/default-message-sender.js +6 -2
- package/components/exchange/message-dispatcher.js +13 -9
- package/components/exchange/message-exchange.js +57 -21
- package/components/exchange/message-memory-cache.js +31 -4
- package/components/exchange/message-tracer.js +138 -92
- package/components/service-caller.js +6 -6
- package/components/service-consumer.js +3 -3
- package/components/service-executor.js +38 -16
- package/components/service-instance.js +46 -28
- package/components/service-provider.js +5 -5
- package/integrations/gcloud-integration.js +3 -2
- package/integrations/redis-integration.js +257 -138
- package/package.json +6 -6
- package/testRedis.js +22 -0
- package/utils/cache.js +44 -14
- package/utils/config.js +9 -1
- package/utils/localization.js +2 -2
- package/utils/logger.js +3 -4
package/utils/cache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
|
|
3
|
-
* Copyright © 2021-
|
|
3
|
+
* Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
|
|
4
4
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
5
5
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
6
6
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
@@ -36,13 +36,6 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
36
36
|
super();
|
|
37
37
|
|
|
38
38
|
if ( !CommonMemoryCache.#instance ) {
|
|
39
|
-
let host = config.getSetting( config.setting.MEMORY_CACHE_REDIS_HOST );
|
|
40
|
-
let port = config.getSetting( config.setting.MEMORY_CACHE_REDIS_PORT );
|
|
41
|
-
let db = config.getSetting( config.setting.MEMORY_CACHE_REDIS_DB );
|
|
42
|
-
let authKey = config.getSetting( config.setting.MEMORY_CACHE_AUTH_KEY );
|
|
43
|
-
let user = config.getSetting( config.setting.MEMORY_CACHE_USER );
|
|
44
|
-
this.#redisClient = redis.createRedisClient( this.#connectionIdentifier, host, port, authKey, user, db );
|
|
45
|
-
this.#redisClient.addConnectionObserver( this );
|
|
46
39
|
CommonMemoryCache.#instance = this;
|
|
47
40
|
}
|
|
48
41
|
return CommonMemoryCache.#instance;
|
|
@@ -57,7 +50,9 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
57
50
|
* @returns {boolean}
|
|
58
51
|
* @public
|
|
59
52
|
*/
|
|
60
|
-
get isOperational() {
|
|
53
|
+
get isOperational() {
|
|
54
|
+
return this.#isOperational;
|
|
55
|
+
}
|
|
61
56
|
|
|
62
57
|
/**
|
|
63
58
|
* Property returning the connection identifier of the cache service.
|
|
@@ -66,7 +61,40 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
66
61
|
* @returns {string}
|
|
67
62
|
* @public
|
|
68
63
|
*/
|
|
69
|
-
get connectionIdentifier() {
|
|
64
|
+
get connectionIdentifier() {
|
|
65
|
+
return this.#connectionIdentifier;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Used to initialize the cache service.
|
|
70
|
+
*
|
|
71
|
+
* @method
|
|
72
|
+
* @returns {Promise}
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
initialize() {
|
|
76
|
+
let host = config.getSetting( config.setting.MEMORY_CACHE_REDIS_HOST );
|
|
77
|
+
let port = config.getSetting( config.setting.MEMORY_CACHE_REDIS_PORT );
|
|
78
|
+
let db = config.getSetting( config.setting.MEMORY_CACHE_REDIS_DB );
|
|
79
|
+
let authKey = config.getSetting( config.setting.MEMORY_CACHE_AUTH_KEY );
|
|
80
|
+
let user = config.getSetting( config.setting.MEMORY_CACHE_USER );
|
|
81
|
+
|
|
82
|
+
this.#redisClient = redis.createRedisClient( this.#connectionIdentifier );
|
|
83
|
+
this.#redisClient.addConnectionObserver( this );
|
|
84
|
+
|
|
85
|
+
return this.#redisClient.initialize( host, port, authKey, user, db );
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Used to gracefully shut down the cache service.
|
|
90
|
+
*
|
|
91
|
+
* @method
|
|
92
|
+
* @return {Promise}
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
shutDown() {
|
|
96
|
+
return this.#redisClient.shutDown( 250 );
|
|
97
|
+
}
|
|
70
98
|
|
|
71
99
|
/**
|
|
72
100
|
* Needs to be invoked by the connection handler when the connection is disrupted.
|
|
@@ -108,7 +136,7 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
108
136
|
}
|
|
109
137
|
|
|
110
138
|
/**
|
|
111
|
-
* Used to search for keys by given pattern.
|
|
139
|
+
* Used to search for keys by a given pattern.
|
|
112
140
|
*
|
|
113
141
|
* @method
|
|
114
142
|
* @param {string} pattern
|
|
@@ -364,7 +392,7 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
364
392
|
/**
|
|
365
393
|
* Used to add multiple values to multiple sets in one transactional request.
|
|
366
394
|
* <br/>
|
|
367
|
-
* NOTE: The two arrays of keys and values must have correct index relations (i.e
|
|
395
|
+
* NOTE: The two arrays of keys and values must have correct index relations (i.e., first pair on keys[0] and values[0] and so on)!
|
|
368
396
|
*
|
|
369
397
|
* @method
|
|
370
398
|
* @param {string[]} keys
|
|
@@ -391,7 +419,7 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
391
419
|
}
|
|
392
420
|
|
|
393
421
|
/**
|
|
394
|
-
* Used to check if the provided value is member of the specified set.
|
|
422
|
+
* Used to check if the provided value is a member of the specified set.
|
|
395
423
|
*
|
|
396
424
|
* @method
|
|
397
425
|
* @param {string} setName
|
|
@@ -470,6 +498,7 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
470
498
|
* Used to set a single hash field.
|
|
471
499
|
*
|
|
472
500
|
* @method
|
|
501
|
+
* @deprecated
|
|
473
502
|
* @param {string} key
|
|
474
503
|
* @param {string} name
|
|
475
504
|
* @param {*} value
|
|
@@ -495,6 +524,7 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
495
524
|
* Used to set multiple hash fields.
|
|
496
525
|
*
|
|
497
526
|
* @method
|
|
527
|
+
* @deprecated
|
|
498
528
|
* @param {string} key
|
|
499
529
|
* @param {Object[]} fields
|
|
500
530
|
* @param {string} fields[].name
|
|
@@ -646,4 +676,4 @@ class CommonMemoryCache extends ConnectionObserver {
|
|
|
646
676
|
}
|
|
647
677
|
|
|
648
678
|
const instance = new CommonMemoryCache();
|
|
649
|
-
module.exports = Object.freeze( instance );
|
|
679
|
+
module.exports.instance = Object.freeze( instance );
|
package/utils/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
|
|
3
|
-
* Copyright © 2021-
|
|
3
|
+
* Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
|
|
4
4
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
5
5
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
6
6
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
@@ -33,6 +33,8 @@ const tools = require( "#tools" );
|
|
|
33
33
|
* @property {EnvironmentVariable} env.TI_MEMORY_CACHE_REDIS_DB
|
|
34
34
|
* @property {EnvironmentVariable} env.TI_MEMORY_CACHE_REDIS_HOST
|
|
35
35
|
* @property {EnvironmentVariable} env.TI_MEMORY_CACHE_REDIS_PORT
|
|
36
|
+
* @property {EnvironmentVariable} env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS
|
|
37
|
+
* @property {EnvironmentVariable} env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL
|
|
36
38
|
* @property {EnvironmentVariable} env.TI_MEMORY_CACHE_USER
|
|
37
39
|
* @property {EnvironmentVariable} env.TI_MESSAGE_EXCHANGE_SECURITY_HASH_ENABLED
|
|
38
40
|
* @property {EnvironmentVariable} env.TI_MESSAGE_EXCHANGE_SECURITY_HASH_KEY
|
|
@@ -80,6 +82,8 @@ const tools = require( "#tools" );
|
|
|
80
82
|
* @property {number} redisDB
|
|
81
83
|
* @property {string} redisHost
|
|
82
84
|
* @property {number} redisPort
|
|
85
|
+
* @property {number} retryMaxAttempts
|
|
86
|
+
* @property {number} retryMaxInterval
|
|
83
87
|
* @property {string} user
|
|
84
88
|
*/
|
|
85
89
|
|
|
@@ -122,6 +126,8 @@ let settingsEnum = tools.enum( {
|
|
|
122
126
|
MEMORY_CACHE_REDIS_DB: [ "memoryCache.redisDB", "redisDB", "" ],
|
|
123
127
|
MEMORY_CACHE_REDIS_HOST: [ "memoryCache.redisHost", "redisHost", "" ],
|
|
124
128
|
MEMORY_CACHE_REDIS_PORT: [ "memoryCache.redisPort", "redisPort", "" ],
|
|
129
|
+
MEMORY_CACHE_RETRY_MAX_ATTEMPTS: [ "memoryCache.retryMaxAttempts", "retryMaxAttempts", "" ],
|
|
130
|
+
MEMORY_CACHE_RETRY_MAX_INTERVAL: [ "memoryCache.retryMaxInterval", "retryMaxInterval", "" ],
|
|
125
131
|
MEMORY_CACHE_USER: [ "memoryCache.user", "user", "" ],
|
|
126
132
|
MESSAGE_EXCHANGE_QUEUE_PREFIX: [ "messageExchange.messageQueuePrefix", "messageQueuePrefix", "" ],
|
|
127
133
|
MESSAGE_EXCHANGE_MESSAGE_STORE: [ "messageExchange.messageStore", "messageStore", "" ],
|
|
@@ -162,6 +168,8 @@ if ( settings.memoryCache ) {
|
|
|
162
168
|
settings.memoryCache.redisDB = ( process.env.TI_MEMORY_CACHE_REDIS_DB !== undefined ) ? process.env.TI_MEMORY_CACHE_REDIS_DB : settings.memoryCache.redisDB;
|
|
163
169
|
settings.memoryCache.redisHost = ( process.env.TI_MEMORY_CACHE_REDIS_HOST !== undefined ) ? process.env.TI_MEMORY_CACHE_REDIS_HOST : settings.memoryCache.redisHost;
|
|
164
170
|
settings.memoryCache.redisPort = ( process.env.TI_MEMORY_CACHE_REDIS_PORT !== undefined ) ? process.env.TI_MEMORY_CACHE_REDIS_PORT : settings.memoryCache.redisPort;
|
|
171
|
+
settings.memoryCache.retryMaxAttempts = ( process.env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS !== undefined ) ? process.env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS : settings.memoryCache.retryMaxAttempts;
|
|
172
|
+
settings.memoryCache.retryMaxInterval = ( process.env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL !== undefined ) ? process.env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL : settings.memoryCache.retryMaxInterval;
|
|
165
173
|
settings.memoryCache.user = ( process.env.TI_MEMORY_CACHE_USER !== undefined ) ? process.env.TI_MEMORY_CACHE_USER : settings.memoryCache.user;
|
|
166
174
|
}
|
|
167
175
|
if ( settings.messageExchange ) {
|
package/utils/localization.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
|
|
3
|
-
* Copyright © 2021-
|
|
3
|
+
* Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
|
|
4
4
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
5
5
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
6
6
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
@@ -27,4 +27,4 @@ Object.freeze( labels );
|
|
|
27
27
|
*/
|
|
28
28
|
module.exports.getLabel = ( label ) => {
|
|
29
29
|
return _.get( labels, label + "." + config.getSetting( config.setting.LOCALIZATION_LANGUAGE ), defaultEmptyLabel );
|
|
30
|
-
};
|
|
30
|
+
};
|
package/utils/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
|
|
3
|
-
* Copyright © 2021-
|
|
3
|
+
* Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
|
|
4
4
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
5
5
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
6
6
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
@@ -72,7 +72,6 @@ const exceptionToLog = ( exception ) => {
|
|
|
72
72
|
* @public
|
|
73
73
|
*/
|
|
74
74
|
module.exports.log = ( message, level = logSeverityEnum.DEFAULT, data = {}, thread = "main" ) => {
|
|
75
|
-
/** @type {Auditing} */
|
|
76
75
|
const auditing = require( "#auditing" );
|
|
77
76
|
|
|
78
77
|
if ( data instanceof Error ) {
|
|
@@ -83,5 +82,5 @@ module.exports.log = ( message, level = logSeverityEnum.DEFAULT, data = {}, thre
|
|
|
83
82
|
data.exception = exceptionToLog( data.exception );
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
auditing.log( message, level, thread, data );
|
|
87
|
-
};
|
|
85
|
+
auditing.instance.log( message, level, thread, data );
|
|
86
|
+
};
|