samanbayaka 0.0.23 → 0.0.25
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/README.md +115 -29
- package/commit-hash.mjs +1 -1
- package/config/kafka.yml +75 -0
- package/config/nats.yml +110 -0
- package/config/openobserve.yml +5 -0
- package/config/redis.yml +19 -0
- package/helper/file/esm-loading.mjs +75 -48
- package/helper/mol-built-in/HybridCacher.mjs +2 -2
- package/helper/utility/config-handler.mjs +116 -0
- package/helper/utility/error-handler.mjs +8 -15
- package/helper/utility/{run-startup-check.mjs → global-configs-validator.mjs} +11 -7
- package/index.mjs +90 -19
- package/package.json +6 -3
- package/public/config-manager.html +627 -0
- package/services/{kafka → kafkajs}/index.mjs +1 -1
- package/services/system/config/server.mjs +36 -0
- package/services/system/index.mjs +243 -0
- package/services/system/metrics.mjs +49 -0
- package/services/system/scalar.mjs +32 -0
- package/services/system/sw-stats-mw.mjs +12 -0
- package/config/catcher.mjs +0 -27
- package/config/kafkajs.mjs +0 -66
- package/config/nats.mjs +0 -189
- package/config/telemetry.mjs +0 -5
- package/public/signin.html +0 -93
package/README.md
CHANGED
|
@@ -17,9 +17,10 @@ This project is a modular, production-ready microservices framework built with M
|
|
|
17
17
|
- [Errors](#errors)
|
|
18
18
|
- [getConfig](#getConfig)
|
|
19
19
|
- [loadDemo](#loadDemo)
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
20
|
+
- [registerSystemAPI](#registerSystemAPI)
|
|
21
|
+
- [registerEdgeAPI](#registerEdgeAPI)
|
|
22
|
+
- [registerServices](#registerServices)
|
|
23
|
+
- [registerBridgeServices](#registerBridgeServices)
|
|
23
24
|
- [Usage](#usage)
|
|
24
25
|
- [Demo](#Demo)
|
|
25
26
|
- [Dockers](#dockers)
|
|
@@ -66,6 +67,9 @@ source /etc/profile.d/sbk.sh
|
|
|
66
67
|
```
|
|
67
68
|
Paste this:
|
|
68
69
|
```bash
|
|
70
|
+
## Credential for reading configurations from the Etcd server, the default port is 2379.
|
|
71
|
+
export SBK_CONFIG_CRED=<yout_user>:<your_pass>:<your_port>
|
|
72
|
+
|
|
69
73
|
## Configurations files path
|
|
70
74
|
export SBK_CONFIG_PATH=/usr/local/etc/<your_folder>
|
|
71
75
|
|
|
@@ -145,18 +149,23 @@ The file is loaded from the configuration directory defined by the environment v
|
|
|
145
149
|
|
|
146
150
|
`sbk.loadDemo` is an asynchronous function that creates a demo service to help understand the project.
|
|
147
151
|
|
|
148
|
-
###
|
|
152
|
+
### registerSystemAPI
|
|
153
|
+
|
|
154
|
+
`sbk.registerSystemAPI` is an asynchronous function that creates a gateway service to expose REST APIs for system management.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
### registerEdgeAPI
|
|
149
158
|
|
|
150
|
-
`sbk.
|
|
159
|
+
`sbk.registerEdgeAPI` is an asynchronous function that creates a gateway service to expose REST APIs.
|
|
151
160
|
|
|
152
|
-
###
|
|
161
|
+
### registerServices
|
|
153
162
|
|
|
154
|
-
`sbk.
|
|
163
|
+
`sbk.registerServices` is an asynchronous function that creates a feature service.
|
|
155
164
|
|
|
156
165
|
##### Function Signature
|
|
157
166
|
|
|
158
167
|
```js
|
|
159
|
-
sbk.
|
|
168
|
+
sbk.registerServices(schema)
|
|
160
169
|
```
|
|
161
170
|
|
|
162
171
|
##### Parameter
|
|
@@ -181,14 +190,14 @@ Example:
|
|
|
181
190
|
```
|
|
182
191
|
|
|
183
192
|
|
|
184
|
-
###
|
|
193
|
+
### registerBridgeServices
|
|
185
194
|
|
|
186
|
-
`sbk.
|
|
195
|
+
`sbk.registerBridgeServices` is a function used to initialize and manage message brokers such as Kafka, MQTT, and RabbitMQ.
|
|
187
196
|
|
|
188
197
|
##### Function Signature
|
|
189
198
|
|
|
190
199
|
```js
|
|
191
|
-
sbk.
|
|
200
|
+
sbk.registerBridgeServices(
|
|
192
201
|
type,
|
|
193
202
|
brokerOpts = {},
|
|
194
203
|
callback = () => {}
|
|
@@ -274,7 +283,7 @@ touch index.mjs
|
|
|
274
283
|
Open `index.mjs` and paste the following:
|
|
275
284
|
```bash
|
|
276
285
|
import sbk from "samanbayaka"
|
|
277
|
-
await sbk.
|
|
286
|
+
await sbk.registerEdgeAPI()
|
|
278
287
|
```
|
|
279
288
|
---
|
|
280
289
|
### Create feature services
|
|
@@ -298,7 +307,7 @@ touch index.mjs
|
|
|
298
307
|
Open `index.mjs` and paste the following:
|
|
299
308
|
```bash
|
|
300
309
|
import sbk from "samanbayaka"
|
|
301
|
-
await sbk.
|
|
310
|
+
await sbk.registerServices({
|
|
302
311
|
name: "hello",
|
|
303
312
|
version: "v1",
|
|
304
313
|
|
|
@@ -357,7 +366,7 @@ touch index.mjs
|
|
|
357
366
|
Open `index.mjs` and paste the following:
|
|
358
367
|
```bash
|
|
359
368
|
import sbk from "samanbayaka"
|
|
360
|
-
await sbk.
|
|
369
|
+
await sbk.registerBridgeServices(
|
|
361
370
|
"kafka",
|
|
362
371
|
{
|
|
363
372
|
name: "producer-kafka-student",
|
|
@@ -396,7 +405,7 @@ touch index.mjs
|
|
|
396
405
|
Open `index.mjs` and paste the following:
|
|
397
406
|
```bash
|
|
398
407
|
import sbk from "samanbayaka"
|
|
399
|
-
await sbk.
|
|
408
|
+
await sbk.registerBridgeServices(
|
|
400
409
|
"kafka",
|
|
401
410
|
{
|
|
402
411
|
name: "consumer-kafka-student",
|
|
@@ -454,14 +463,15 @@ node demo.mjs
|
|
|
454
463
|
## Dockers
|
|
455
464
|
|
|
456
465
|
### Etcd
|
|
457
|
-
To manage configurations centrally, use the docker-compose.yml file to run Etcd
|
|
466
|
+
To manage configurations centrally, use the docker-compose.yml file to run Etcd and All `.yml` configuration files must be deployed to /usr/local/etc/<your_project_name>.
|
|
458
467
|
```bash
|
|
459
468
|
mkdir -p etcd
|
|
460
469
|
cd etcd
|
|
461
470
|
touch docker-compose.yml
|
|
462
471
|
export ETCD_ROOT_PW=<your_root_pass>
|
|
463
472
|
export ETCD_CONFIG_ADMIN_PW=<your_config_admin_pass>
|
|
464
|
-
|
|
473
|
+
mkdir -p /usr/local/etc/<your_project_name>
|
|
474
|
+
```
|
|
465
475
|
|
|
466
476
|
Open `docker-compose.yml` and paste the following:
|
|
467
477
|
```yml
|
|
@@ -475,7 +485,7 @@ services:
|
|
|
475
485
|
- "<your_cluster_port>:2380"
|
|
476
486
|
|
|
477
487
|
volumes:
|
|
478
|
-
- /usr/local/etc
|
|
488
|
+
- /usr/local/etc/<your_project_name>:/etcd-data
|
|
479
489
|
|
|
480
490
|
command:
|
|
481
491
|
- /usr/local/bin/etcd
|
|
@@ -496,7 +506,7 @@ services:
|
|
|
496
506
|
- etcd
|
|
497
507
|
|
|
498
508
|
volumes:
|
|
499
|
-
- /usr/local/etc
|
|
509
|
+
- /usr/local/etc/<your_project_name>:/etcd-data
|
|
500
510
|
|
|
501
511
|
environment:
|
|
502
512
|
- ETCDCTL_API=3
|
|
@@ -548,25 +558,101 @@ services:
|
|
|
548
558
|
# ---------------------------------------------------------
|
|
549
559
|
|
|
550
560
|
echo "Creating Roles and Granting"
|
|
551
|
-
|
|
552
|
-
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role
|
|
553
|
-
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true
|
|
554
|
-
|
|
555
|
-
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role
|
|
561
|
+
|
|
562
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add default
|
|
563
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true default read /config/sbk/global/
|
|
564
|
+
|
|
565
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add edge
|
|
566
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true edge read /config/sbk/edge/
|
|
567
|
+
|
|
568
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add bridge
|
|
569
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true bridge read /config/sbk/bridge/
|
|
570
|
+
|
|
571
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add sap
|
|
572
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true sap read /config/sbk/sap/
|
|
573
|
+
|
|
574
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add dbs
|
|
575
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true dbs read /config/sbk/dbs/
|
|
576
|
+
|
|
577
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add msg
|
|
578
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true msg read /config/sbk/msg/
|
|
556
579
|
|
|
557
580
|
# ---------------------------------------------------------
|
|
558
581
|
|
|
559
582
|
echo "Creating User and Assign Role"
|
|
560
|
-
|
|
561
|
-
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user
|
|
583
|
+
|
|
584
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add sbk:<your_pass>
|
|
585
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role sbk default
|
|
586
|
+
|
|
587
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add apigw:<your_pass>
|
|
588
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role apigw default
|
|
589
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role apigw edge
|
|
590
|
+
|
|
591
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add msgbus:<your_pass>
|
|
592
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msgbus default
|
|
593
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msgbus bridge
|
|
594
|
+
|
|
595
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add sap:<your_pass>
|
|
596
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role sap default
|
|
597
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role sap sap
|
|
598
|
+
|
|
599
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add dbs:<your_pass>
|
|
600
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role dbs default
|
|
601
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role dbs dbs
|
|
602
|
+
|
|
603
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add msg:<your_pass>
|
|
604
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msg default
|
|
605
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msg msg
|
|
562
606
|
|
|
563
607
|
# ---------------------------------------------------------
|
|
564
608
|
|
|
565
|
-
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/yaml/nats "$(cat /etcd-data/nats.yml)" || true
|
|
609
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/broker/yaml/nats "$(cat /etcd-data/nats.yml)" || true
|
|
610
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/catcher/yaml/redis "$(cat /etcd-data/redis.yml)" || true
|
|
611
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/telemetry/yaml/openobserve "$(cat /etcd-data/openobserve.yml)" || true
|
|
612
|
+
|
|
613
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/edge/yaml/auth "$(cat /etcd-data/auth.yml)" || true
|
|
614
|
+
|
|
615
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/bridge/yaml/kafka "$(cat /etcd-data/kafka.yml)" || true
|
|
616
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/bridge/yaml/mqtt "$(cat /etcd-data/mqtt.yml)" || true
|
|
617
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/bridge/yaml/amqp "$(cat /etcd-data/amqp.yml)" || true
|
|
618
|
+
|
|
619
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/sap/yaml/isu "$(cat /etcd-data/isu.yml)" || true
|
|
620
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/sap/yaml/erp "$(cat /etcd-data/erp.yml)" || true
|
|
621
|
+
|
|
622
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/gisdb "$(cat /etcd-data/gisdb.yml)" || true
|
|
623
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/geomdb "$(cat /etcd-data/geomdb.yml)" || true
|
|
624
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/acmadb "$(cat /etcd-data/acmadb.yml)" || true
|
|
625
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/isudb "$(cat /etcd-data/isudb.yml)" || true
|
|
626
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/crmdb "$(cat /etcd-data/crmdb.yml)" || true
|
|
627
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/mdasdb "$(cat /etcd-data/mdasdb.yml)" || true
|
|
628
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/route-sms "$(cat /etcd-data/route-sms.yml)" || true
|
|
629
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/route-otp "$(cat /etcd-data/route-otp.yml)" || true
|
|
630
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/outlook "$(cat /etcd-data/outlook.yml)" || true
|
|
566
631
|
|
|
567
|
-
|
|
632
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/edge/port/api 8765 || true
|
|
633
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/edge/port/sysapi 9876 || true
|
|
634
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/edge/asset/path public || true
|
|
568
635
|
|
|
569
636
|
|
|
637
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/APP_ENV development || true
|
|
638
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/LOG_LEVEL info || true
|
|
639
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/MAX_L1_TTL 120 || true
|
|
640
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/MAX_L2_TTL 600 || true
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/system add || true
|
|
644
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/system/envs/LOG_LEVEL error || true
|
|
645
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/system/envs/MAX_L1_TTL 0 || true
|
|
646
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/system/envs/MAX_L2_TTL 0 || true
|
|
647
|
+
|
|
648
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/gateway add || true
|
|
649
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/test add || true
|
|
650
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/sms add || true
|
|
651
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/members/email add || true
|
|
652
|
+
|
|
653
|
+
#etcdctl --endpoints=http://etcd:2379 --user=<your_user>:<your_pass> get /config/sbk/ --prefix
|
|
654
|
+
#etcdctl --endpoints=http://etcd:2379 --user=<your_user>:<your_pass> get /config/sbk/global/app_env
|
|
655
|
+
|
|
570
656
|
echo "etcd initialization completed"
|
|
571
657
|
```
|
|
572
658
|
Optionally verify:
|
|
@@ -581,4 +667,4 @@ docker exec -it sbk-etcd etcdctl --endpoints=http://etcd:2379 endpoint health
|
|
|
581
667
|
|
|
582
668
|
<p align="center" style="margin-top: 100px;">
|
|
583
669
|
<img src="https://moleculer.services/images/banner.png" alt="Moleculer Logo" width="600">
|
|
584
|
-
</p>
|
|
670
|
+
</p>
|
package/commit-hash.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const COMMIT_HASH = '
|
|
1
|
+
export const COMMIT_HASH = '08f296a';
|
package/config/kafka.yml
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# kafka.yml
|
|
2
|
+
|
|
3
|
+
client:
|
|
4
|
+
clientId: node-client123
|
|
5
|
+
|
|
6
|
+
brokers:
|
|
7
|
+
- pnsntst.wbsedcl.in:9092
|
|
8
|
+
|
|
9
|
+
connectionTimeout: 20000
|
|
10
|
+
requestTimeout: 20000
|
|
11
|
+
enforceRequestTimeout: true
|
|
12
|
+
|
|
13
|
+
retry:
|
|
14
|
+
maxRetryTime: 60000
|
|
15
|
+
initialRetryTime: 300
|
|
16
|
+
factor: 0.2
|
|
17
|
+
multiplier: 2
|
|
18
|
+
retries: 5
|
|
19
|
+
|
|
20
|
+
ssl:
|
|
21
|
+
rejectUnauthorized: true
|
|
22
|
+
|
|
23
|
+
sasl:
|
|
24
|
+
mechanism: scram-sha-256
|
|
25
|
+
username: bob
|
|
26
|
+
password: SUhcznwt0xopsTfDXKIPzgw66dzJpZ
|
|
27
|
+
|
|
28
|
+
producer:
|
|
29
|
+
retry:
|
|
30
|
+
initialRetryTime: 300
|
|
31
|
+
retries: 8
|
|
32
|
+
maxRetryTime: 30000
|
|
33
|
+
factor: 0.2
|
|
34
|
+
multiplier: 2
|
|
35
|
+
|
|
36
|
+
metadataMaxAge: 300000
|
|
37
|
+
allowAutoTopicCreation: false
|
|
38
|
+
transactionTimeout: 30000
|
|
39
|
+
idempotent: true
|
|
40
|
+
maxInFlightRequests: 1
|
|
41
|
+
|
|
42
|
+
consumer:
|
|
43
|
+
groupId: default
|
|
44
|
+
|
|
45
|
+
# partitionAssigners: []
|
|
46
|
+
|
|
47
|
+
sessionTimeout: 30000
|
|
48
|
+
rebalanceTimeout: 60000
|
|
49
|
+
heartbeatInterval: 5000
|
|
50
|
+
|
|
51
|
+
metadataMaxAge: 300000
|
|
52
|
+
allowAutoTopicCreation: false
|
|
53
|
+
|
|
54
|
+
maxBytesPerPartition: 1048576
|
|
55
|
+
minBytes: 1
|
|
56
|
+
maxBytes: 10485760
|
|
57
|
+
maxWaitTimeInMs: 5000
|
|
58
|
+
|
|
59
|
+
retry:
|
|
60
|
+
initialRetryTime: 300
|
|
61
|
+
retries: 8
|
|
62
|
+
maxRetryTime: 30000
|
|
63
|
+
factor: 0.2
|
|
64
|
+
multiplier: 2
|
|
65
|
+
|
|
66
|
+
maxInFlightRequests: 1
|
|
67
|
+
|
|
68
|
+
# rackId: null
|
|
69
|
+
# interMessageDelayMs: 10
|
|
70
|
+
|
|
71
|
+
logLevel: INFO
|
|
72
|
+
|
|
73
|
+
gzip: true
|
|
74
|
+
msgPack: true
|
|
75
|
+
rest: false
|
package/config/nats.yml
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# broker.yml
|
|
2
|
+
|
|
3
|
+
namespace: sbk
|
|
4
|
+
|
|
5
|
+
requestTimeout: 10000
|
|
6
|
+
|
|
7
|
+
retryPolicy:
|
|
8
|
+
enabled: true
|
|
9
|
+
retries: 3
|
|
10
|
+
delay: 200
|
|
11
|
+
maxDelay: 3000
|
|
12
|
+
factor: 2
|
|
13
|
+
check: null # err => err && !!err.retryable
|
|
14
|
+
|
|
15
|
+
contextParamsCloning: false
|
|
16
|
+
|
|
17
|
+
maxCallLevel: 100
|
|
18
|
+
|
|
19
|
+
heartbeatInterval: 5
|
|
20
|
+
heartbeatTimeout: 20
|
|
21
|
+
|
|
22
|
+
tracking:
|
|
23
|
+
enabled: true
|
|
24
|
+
shutdownTimeout: 10000
|
|
25
|
+
|
|
26
|
+
disableBalancer: false
|
|
27
|
+
|
|
28
|
+
registry:
|
|
29
|
+
strategy: RoundRobin
|
|
30
|
+
preferLocal: true
|
|
31
|
+
|
|
32
|
+
circuitBreaker:
|
|
33
|
+
enabled: true
|
|
34
|
+
threshold: 0.5
|
|
35
|
+
minRequestCount: 50
|
|
36
|
+
windowTime: 60
|
|
37
|
+
halfOpenTime: 10000
|
|
38
|
+
|
|
39
|
+
bulkhead:
|
|
40
|
+
enabled: true
|
|
41
|
+
concurrency: 50
|
|
42
|
+
maxQueueSize: 200
|
|
43
|
+
|
|
44
|
+
metrics:
|
|
45
|
+
enabled: false
|
|
46
|
+
# reporter:
|
|
47
|
+
# - type: Prometheus
|
|
48
|
+
# options:
|
|
49
|
+
# port: 3030
|
|
50
|
+
|
|
51
|
+
tracing:
|
|
52
|
+
enabled: false
|
|
53
|
+
# exporter:
|
|
54
|
+
# - Console
|
|
55
|
+
|
|
56
|
+
transit:
|
|
57
|
+
maxQueueSize: 50000
|
|
58
|
+
disableReconnect: false
|
|
59
|
+
disableVersionCheck: false
|
|
60
|
+
packetLogFilter:
|
|
61
|
+
- HEARTBEAT
|
|
62
|
+
|
|
63
|
+
uidGenerator: null
|
|
64
|
+
|
|
65
|
+
errorHandler: null
|
|
66
|
+
|
|
67
|
+
# cacher: MemoryLRU
|
|
68
|
+
|
|
69
|
+
serializer: MsgPack
|
|
70
|
+
|
|
71
|
+
validator: true
|
|
72
|
+
|
|
73
|
+
errorRegenerator: null
|
|
74
|
+
|
|
75
|
+
internalServices: true
|
|
76
|
+
internalMiddlewares: true
|
|
77
|
+
|
|
78
|
+
hotReload: false
|
|
79
|
+
|
|
80
|
+
# middlewares:
|
|
81
|
+
# - MyMiddleware
|
|
82
|
+
|
|
83
|
+
replOptions:
|
|
84
|
+
delimiter: "mol # "
|
|
85
|
+
customCommands:
|
|
86
|
+
- command: "hello <name>"
|
|
87
|
+
action: null
|
|
88
|
+
|
|
89
|
+
metadata:
|
|
90
|
+
# region: eu-west1
|
|
91
|
+
|
|
92
|
+
logger: CustomPino
|
|
93
|
+
logLevel: error
|
|
94
|
+
|
|
95
|
+
transporter:
|
|
96
|
+
type: NATS
|
|
97
|
+
options:
|
|
98
|
+
servers:
|
|
99
|
+
- nats://nats:4222
|
|
100
|
+
|
|
101
|
+
user: nats
|
|
102
|
+
pass: nats123
|
|
103
|
+
|
|
104
|
+
reconnect: true
|
|
105
|
+
maxReconnectAttempts: -1
|
|
106
|
+
reconnectTimeWait: 2000
|
|
107
|
+
waitOnFirstConnect: true
|
|
108
|
+
|
|
109
|
+
maxInFlight: 1000
|
|
110
|
+
timeout: 5000
|
package/config/redis.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# cacher.yml
|
|
2
|
+
|
|
3
|
+
max: 200
|
|
4
|
+
|
|
5
|
+
# Time-to-Live in seconds
|
|
6
|
+
ttl:
|
|
7
|
+
- 600
|
|
8
|
+
- 120
|
|
9
|
+
|
|
10
|
+
redis:
|
|
11
|
+
# Turns Redis client monitoring on
|
|
12
|
+
monitor: false
|
|
13
|
+
|
|
14
|
+
# Redis connection settings
|
|
15
|
+
host: redis
|
|
16
|
+
port: 6379
|
|
17
|
+
|
|
18
|
+
# password: "1234"
|
|
19
|
+
# db: 0
|
|
@@ -15,16 +15,6 @@ const __dirname = path.dirname(__filename)
|
|
|
15
15
|
const require = createRequire(import.meta.url)
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
const [user, pass] = (process.env.SBK_CONFIG_URPW || "ur:pa").split(":")
|
|
19
|
-
|
|
20
|
-
const client = new Etcd3({
|
|
21
|
-
hosts: "http://etcd:12379",
|
|
22
|
-
auth: {
|
|
23
|
-
username: user,
|
|
24
|
-
password: pass
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
18
|
/**
|
|
29
19
|
* Configuration path
|
|
30
20
|
* @type {string}
|
|
@@ -51,58 +41,95 @@ export const DEMO_SERVICES_DIR = path.join(ABSOLUTE_PATH, 'services', 'demo')
|
|
|
51
41
|
const SERVICES_DIR = __dirname.split('node_modules')[0]
|
|
52
42
|
|
|
53
43
|
|
|
44
|
+
/**
|
|
45
|
+
* User credentials for accessing and reading configurations from
|
|
46
|
+
* the configuration server.
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
const [configUser, ConfigPass, configPort] = (process.env.SBK_CONFIG_CRED || "ur:pa:2379").split(":")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Configuration Reader Client Options
|
|
54
|
+
* @type {object}
|
|
55
|
+
*/
|
|
56
|
+
const client = new Etcd3({
|
|
57
|
+
hosts: `http://etcd:${configPort}`,
|
|
58
|
+
auth: {
|
|
59
|
+
username: configUser,
|
|
60
|
+
password: ConfigPass
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
|
|
54
65
|
/**
|
|
55
66
|
* Getting configurations through dynamic loading of ESM modules
|
|
56
67
|
* ftom the path defined in environment variable
|
|
57
68
|
* @param {string}
|
|
58
69
|
* @return {object}
|
|
59
70
|
*/
|
|
60
|
-
export const getConfig = async (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
export const getConfig = async (path) => {
|
|
72
|
+
try {
|
|
73
|
+
const yamlText = await client.get(`/config${path}`)
|
|
74
|
+
if ( path.startsWith("/yaml/") ) {
|
|
75
|
+
return Object.freeze( YAML.parse(yamlText?.toString()) )
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return yamlText?.toString()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} catch (err) {
|
|
82
|
+
throw new Error(`Unable to read configuration : ${err.message}`)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
75
85
|
|
|
76
|
-
// return (await import(pathToFileURL(configFile).href)).default
|
|
77
86
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
export const watchConfig = async (path, callback) => {
|
|
88
|
+
const watcher = await client
|
|
89
|
+
.watch()
|
|
90
|
+
.prefix(`/config${path}`)
|
|
91
|
+
.create()
|
|
92
|
+
|
|
93
|
+
watcher.on("put", event => {
|
|
94
|
+
const evVal = path.startsWith("/yaml/")
|
|
95
|
+
? Object.freeze( YAML.parse(event.value.toString()) )
|
|
96
|
+
: event.value?.toString()
|
|
97
|
+
callback(
|
|
98
|
+
"put",
|
|
99
|
+
event.key?.toString(),
|
|
100
|
+
evVal
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
watcher.on("delete", event => {
|
|
105
|
+
callback(
|
|
106
|
+
"delete",
|
|
107
|
+
event.key.toString(),
|
|
108
|
+
null
|
|
82
109
|
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// }
|
|
110
|
+
})
|
|
111
|
+
|
|
86
112
|
}
|
|
87
113
|
|
|
88
114
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Getting server configuration.
|
|
118
|
+
* @type {string}
|
|
119
|
+
*/
|
|
120
|
+
const CONFIG = {assetPath: "public"} // await getConfig('server')
|
|
94
121
|
|
|
95
122
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Assets path
|
|
125
|
+
*/
|
|
126
|
+
export const assetPath = {
|
|
127
|
+
rootFolder: path
|
|
128
|
+
.join(
|
|
129
|
+
ABSOLUTE_PATH,
|
|
130
|
+
CONFIG.assetPath,
|
|
131
|
+
),
|
|
132
|
+
}
|
|
106
133
|
|
|
107
134
|
|
|
108
135
|
/**
|
|
@@ -94,9 +94,9 @@ export default class HybridCacher extends Cachers.Base {
|
|
|
94
94
|
const safeL1TTL = Math.min(L1TTL, globalTTL[1], MAX_L1_TTL)
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* Store in Redis (L2) when safeL2TTL > 0 and safeL2TTL > safeL1TTL
|
|
98
98
|
*/
|
|
99
|
-
if( safeL2TTL > safeL1TTL ){
|
|
99
|
+
if( safeL2TTL > 0 && safeL2TTL > safeL1TTL ){
|
|
100
100
|
await this.redis.set(key, {result:data, ttl:[safeL2TTL, safeL1TTL], txnTs: Date.now()}, safeL2TTL)
|
|
101
101
|
}
|
|
102
102
|
|