samanbayaka 0.0.23 → 0.0.26
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 +134 -33
- 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 +15 -61
- package/helper/mol-built-in/CustomLogger.mjs +13 -8
- package/helper/mol-built-in/HybridCacher.mjs +4 -4
- package/helper/utility/config-handler.mjs +122 -0
- package/helper/utility/error-handler.mjs +66 -59
- package/helper/utility/global-configs-validator.mjs +45 -0
- package/helper/utility/telemetry.mjs +2 -6
- package/index.mjs +216 -119
- package/package.json +6 -3
- package/public/config-manager.html +627 -0
- package/services/gateway/index.mjs +9 -3
- package/services/{kafka → kafkajs}/index.mjs +3 -3
- package/services/system/config/server.mjs +36 -0
- package/services/system/index.mjs +316 -0
- package/services/system/metrics.mjs +49 -0
- package/services/system/scalar.mjs +31 -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/helper/utility/run-startup-check.mjs +0 -31
- 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",
|
|
@@ -418,18 +427,30 @@ The `interMessageDelayMs` option introduces a delay between two consecutive mess
|
|
|
418
427
|
### Run the services
|
|
419
428
|
|
|
420
429
|
* development/testing
|
|
430
|
+
|
|
421
431
|
```bash
|
|
422
432
|
cd <your_path>/gateway
|
|
423
|
-
node index.mjs
|
|
433
|
+
SBK_CONFIG_CRED='<your_etcs_user> <your_etcd_pass> <your_etcd_port>' node index.mjs
|
|
424
434
|
cd <your_path>/hello
|
|
425
|
-
node index.mjs
|
|
435
|
+
SBK_CONFIG_CRED='<your_etcs_user> <your_etcd_pass> <your_etcd_port>' node index.mjs
|
|
426
436
|
```
|
|
437
|
+
or
|
|
438
|
+
```bash
|
|
439
|
+
pm2 stop "$(basename "$PWD")" && rm -rf node_modules/samanbayaka/ &&cp -r ../../samanbayaka/. node_modules/samanbayaka/ && SBK_CONFIG_CRED='sbk sbk@123 12379' pm2 start index.mjs --name "$(basename "$PWD")" --stop-exit-codes 1 --output /var/log/samanbayaka/sbk-out-${HOSTNAME}-$$.log --error /var/log/samanbayaka/sbk-err-${HOSTNAME}-$$.log
|
|
440
|
+
```
|
|
427
441
|
* production
|
|
428
442
|
```bash
|
|
429
443
|
cd <your_path>/gateway
|
|
430
|
-
node index.mjs >> /var/log/samanbayaka/sbk-${HOSTNAME}-$$.log 2>&1
|
|
444
|
+
SBK_CONFIG_CRED='<your_etcs_user> <your_etcd_pass> <your_etcd_port>' node index.mjs >> /var/log/samanbayaka/sbk-${HOSTNAME}-$$.log 2>&1
|
|
431
445
|
cd <your_path>/hello
|
|
432
|
-
node index.mjs >> /var/log/samanbayaka/sbk-${HOSTNAME}-$$.log 2>&1
|
|
446
|
+
SBK_CONFIG_CRED='<your_etcs_user> <your_etcd_pass> <your_etcd_port>' node index.mjs >> /var/log/samanbayaka/sbk-${HOSTNAME}-$$.log 2>&1
|
|
447
|
+
```
|
|
448
|
+
or
|
|
449
|
+
```bash
|
|
450
|
+
cd <your_path>/gateway
|
|
451
|
+
SBK_CONFIG_CRED='<your_etcs_user> <your_etcd_pass> <your_etcd_port>' pm2 start index.mjs --name "$(basename "$PWD")" --stop-exit-codes 1 --output /var/log/samanbayaka/sbk-out-${HOSTNAME}-$$.log --error /var/log/samanbayaka/sbk-err-${HOSTNAME}-$$.log
|
|
452
|
+
cd <your_path>/hello
|
|
453
|
+
SBK_CONFIG_CRED='<your_etcs_user> <your_etcd_pass> <your_etcd_port>' pm2 start index.mjs --name "$(basename "$PWD")" --stop-exit-codes 1 --output /var/log/samanbayaka/sbk-out-${HOSTNAME}-$$.log --error /var/log/samanbayaka/sbk-err-${HOSTNAME}-$$.log
|
|
433
454
|
```
|
|
434
455
|
|
|
435
456
|
## Demo
|
|
@@ -454,14 +475,15 @@ node demo.mjs
|
|
|
454
475
|
## Dockers
|
|
455
476
|
|
|
456
477
|
### Etcd
|
|
457
|
-
To manage configurations centrally, use the docker-compose.yml file to run Etcd
|
|
478
|
+
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
479
|
```bash
|
|
459
480
|
mkdir -p etcd
|
|
460
481
|
cd etcd
|
|
461
482
|
touch docker-compose.yml
|
|
462
483
|
export ETCD_ROOT_PW=<your_root_pass>
|
|
463
484
|
export ETCD_CONFIG_ADMIN_PW=<your_config_admin_pass>
|
|
464
|
-
|
|
485
|
+
sudo mkdir -p /usr/local/etc/<your_project_name>
|
|
486
|
+
```
|
|
465
487
|
|
|
466
488
|
Open `docker-compose.yml` and paste the following:
|
|
467
489
|
```yml
|
|
@@ -475,7 +497,7 @@ services:
|
|
|
475
497
|
- "<your_cluster_port>:2380"
|
|
476
498
|
|
|
477
499
|
volumes:
|
|
478
|
-
- /usr/local/etc
|
|
500
|
+
- /usr/local/etc/<your_project_name>:/etcd-data
|
|
479
501
|
|
|
480
502
|
command:
|
|
481
503
|
- /usr/local/bin/etcd
|
|
@@ -496,7 +518,7 @@ services:
|
|
|
496
518
|
- etcd
|
|
497
519
|
|
|
498
520
|
volumes:
|
|
499
|
-
- /usr/local/etc
|
|
521
|
+
- /usr/local/etc/<your_project_name>:/etcd-data
|
|
500
522
|
|
|
501
523
|
environment:
|
|
502
524
|
- ETCDCTL_API=3
|
|
@@ -548,24 +570,103 @@ services:
|
|
|
548
570
|
# ---------------------------------------------------------
|
|
549
571
|
|
|
550
572
|
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
|
-
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true
|
|
555
|
-
|
|
573
|
+
|
|
574
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add default
|
|
575
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true default read /config/sbk/global/
|
|
576
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true default read /config/sbk/members/
|
|
577
|
+
|
|
578
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add edge
|
|
579
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true edge read /config/sbk/edge/
|
|
580
|
+
|
|
581
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add bridge
|
|
582
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true bridge read /config/sbk/bridge/
|
|
583
|
+
|
|
584
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add sap
|
|
585
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true sap read /config/sbk/sap/
|
|
586
|
+
|
|
587
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add dbs
|
|
588
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true dbs read /config/sbk/dbs/
|
|
589
|
+
|
|
590
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add msg
|
|
591
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true msg read /config/sbk/msg/
|
|
556
592
|
|
|
557
593
|
# ---------------------------------------------------------
|
|
558
594
|
|
|
559
595
|
echo "Creating User and Assign Role"
|
|
560
|
-
|
|
561
|
-
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user
|
|
596
|
+
|
|
597
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add sbk:<your_pass>
|
|
598
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role sbk default
|
|
599
|
+
|
|
600
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add apigw:<your_pass>
|
|
601
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role apigw default
|
|
602
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role apigw edge
|
|
603
|
+
|
|
604
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add msgbus:<your_pass>
|
|
605
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msgbus default
|
|
606
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msgbus bridge
|
|
607
|
+
|
|
608
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add sap:<your_pass>
|
|
609
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role sap default
|
|
610
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role sap sap
|
|
611
|
+
|
|
612
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add dbs:<your_pass>
|
|
613
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role dbs default
|
|
614
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role dbs dbs
|
|
615
|
+
|
|
616
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add msg:<your_pass>
|
|
617
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msg default
|
|
618
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role msg msg
|
|
562
619
|
|
|
563
620
|
# ---------------------------------------------------------
|
|
621
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/REVISION "" || true
|
|
622
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/APP_ENV development || true
|
|
623
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/LOG_LEVEL warn || true
|
|
624
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/MAX_L1_TTL 120 || true
|
|
625
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/MAX_L2_TTL 600 || true
|
|
626
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/envs/TELEMETRY false || true
|
|
627
|
+
|
|
628
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/broker/yaml/nats "$(cat /etcd-data/nats.yml)" || true
|
|
629
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/catcher/yaml/redis "$(cat /etcd-data/redis.yml)" || true
|
|
630
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/global/telemetry/yaml/openobserve "$(cat /etcd-data/openobserve.yml)" || true
|
|
631
|
+
|
|
632
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/edge/yaml/auth "$(cat /etcd-data/auth.yml)" || true
|
|
633
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/edge/asset/path public || true
|
|
634
|
+
|
|
635
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/bridge/yaml/kafka "$(cat /etcd-data/kafka.yml)" || true
|
|
636
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/bridge/yaml/mqtt "$(cat /etcd-data/mqtt.yml)" || true
|
|
637
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/bridge/yaml/amqp "$(cat /etcd-data/amqp.yml)" || true
|
|
638
|
+
|
|
639
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/sap/yaml/isu "$(cat /etcd-data/isu.yml)" || true
|
|
640
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/sap/yaml/erp "$(cat /etcd-data/erp.yml)" || true
|
|
641
|
+
|
|
642
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/gisdb "$(cat /etcd-data/gisdb.yml)" || true
|
|
643
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/geomdb "$(cat /etcd-data/geomdb.yml)" || true
|
|
644
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/acmadb "$(cat /etcd-data/acmadb.yml)" || true
|
|
645
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/isudb "$(cat /etcd-data/isudb.yml)" || true
|
|
646
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/crmdb "$(cat /etcd-data/crmdb.yml)" || true
|
|
647
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/mdasdb "$(cat /etcd-data/mdasdb.yml)" || true
|
|
648
|
+
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
|
|
649
|
+
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
|
|
650
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/dbs/pg/yaml/outlook "$(cat /etcd-data/outlook.yml)" || true
|
|
651
|
+
|
|
652
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/demo true || true
|
|
653
|
+
|
|
654
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/system true || true
|
|
655
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/system/envs/PORT 8765 || true
|
|
656
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/system/envs/BROADCAST_INTERVAL 600000 || true
|
|
657
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/system/envs/LOG_LEVEL error || true
|
|
658
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/system/envs/MAX_L1_TTL 0 || true
|
|
659
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/system/envs/MAX_L2_TTL 0 || true
|
|
564
660
|
|
|
565
|
-
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/
|
|
661
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/gateway true || true
|
|
662
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/gateway/envs/PORT 9876 || true
|
|
566
663
|
|
|
567
|
-
|
|
664
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/test true || true
|
|
665
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/sms add || true
|
|
666
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/sbk/members/email add || true
|
|
568
667
|
|
|
668
|
+
#etcdctl --endpoints=http://etcd:2379 --user=<your_user>:<your_pass> get /config/sbk/ --prefix
|
|
669
|
+
#etcdctl --endpoints=http://etcd:2379 --user=<your_user>:<your_pass> get /config/sbk/global/app_env
|
|
569
670
|
|
|
570
671
|
echo "etcd initialization completed"
|
|
571
672
|
```
|
|
@@ -581,4 +682,4 @@ docker exec -it sbk-etcd etcdctl --endpoints=http://etcd:2379 endpoint health
|
|
|
581
682
|
|
|
582
683
|
<p align="center" style="margin-top: 100px;">
|
|
583
684
|
<img src="https://moleculer.services/images/banner.png" alt="Moleculer Logo" width="600">
|
|
584
|
-
</p>
|
|
685
|
+
</p>
|
package/commit-hash.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const COMMIT_HASH = '
|
|
1
|
+
export const COMMIT_HASH = '2a7a879';
|
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: CustomLogger
|
|
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
|
|
@@ -7,23 +7,17 @@ import os from "os"
|
|
|
7
7
|
import { createRequire } from 'module'
|
|
8
8
|
|
|
9
9
|
import chokidar from "chokidar"
|
|
10
|
-
import
|
|
11
|
-
import YAML from 'yaml'
|
|
10
|
+
import * as configHld from '#hUti/config-handler.mjs'
|
|
12
11
|
|
|
13
12
|
const __filename = fileURLToPath(import.meta.url)
|
|
14
13
|
const __dirname = path.dirname(__filename)
|
|
15
14
|
const require = createRequire(import.meta.url)
|
|
16
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Edge configs
|
|
18
|
+
*/
|
|
19
|
+
const EC_ASSET_PATH = (await configHld.getConfigs(`/config/sbk/edge/asset/path`)) || "public"
|
|
17
20
|
|
|
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
21
|
|
|
28
22
|
/**
|
|
29
23
|
* Configuration path
|
|
@@ -48,63 +42,23 @@ export const DEMO_SERVICES_DIR = path.join(ABSOLUTE_PATH, 'services', 'demo')
|
|
|
48
42
|
/**
|
|
49
43
|
* Feature services absolute path
|
|
50
44
|
*/
|
|
51
|
-
const SERVICES_DIR = __dirname
|
|
45
|
+
const SERVICES_DIR = /node_modules/.test(__dirname)
|
|
46
|
+
? __dirname.split('node_modules')[0]
|
|
47
|
+
: __dirname.replace("/helper/file","")
|
|
52
48
|
|
|
53
49
|
|
|
54
50
|
/**
|
|
55
|
-
*
|
|
56
|
-
* ftom the path defined in environment variable
|
|
57
|
-
* @param {string}
|
|
58
|
-
* @return {object}
|
|
51
|
+
* Assets path
|
|
59
52
|
*/
|
|
60
|
-
export const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// // /**
|
|
68
|
-
// // * Validate Configuration
|
|
69
|
-
// // */
|
|
70
|
-
// // if(process.env.NODE_ENV){
|
|
71
|
-
// // console.error("NODE_ENV must be 'production', 'testing', or 'development'")
|
|
72
|
-
// // process.exit(0)
|
|
73
|
-
// // }
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// return (await import(pathToFileURL(configFile).href)).default
|
|
77
|
-
|
|
78
|
-
// try {
|
|
79
|
-
const yamlText = await client.get(`/config/yaml/${fileName}`)
|
|
80
|
-
return Object.freeze(
|
|
81
|
-
YAML.parse(yamlText)
|
|
82
|
-
)
|
|
83
|
-
// } catch (err) {
|
|
84
|
-
// throw new Error(`Configuration reading error: ${err.message}`)
|
|
85
|
-
// }
|
|
53
|
+
export const assetPath = {
|
|
54
|
+
rootFolder: path
|
|
55
|
+
.join(
|
|
56
|
+
ABSOLUTE_PATH,
|
|
57
|
+
EC_ASSET_PATH,
|
|
58
|
+
),
|
|
86
59
|
}
|
|
87
60
|
|
|
88
61
|
|
|
89
|
-
// /**
|
|
90
|
-
// * Getting server configuration.
|
|
91
|
-
// * @type {string}
|
|
92
|
-
// */
|
|
93
|
-
// const CONFIG = await getConfig('server')
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// /**
|
|
97
|
-
// * Assets path
|
|
98
|
-
// */
|
|
99
|
-
// export const assetPath = {
|
|
100
|
-
// rootFolder: path
|
|
101
|
-
// .join(
|
|
102
|
-
// ABSOLUTE_PATH,
|
|
103
|
-
// CONFIG.assetPath,
|
|
104
|
-
// ),
|
|
105
|
-
// }
|
|
106
|
-
|
|
107
|
-
|
|
108
62
|
/**
|
|
109
63
|
* Read package.json file and return object
|
|
110
64
|
* @param {strig} filePath
|
|
@@ -65,12 +65,17 @@ const pinoOptions = {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
export default {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
options:
|
|
68
|
+
export default (opts) => {
|
|
69
|
+
const { logger, logLevel } = opts
|
|
70
|
+
return logger == "CustomLogger"
|
|
71
|
+
? {
|
|
72
|
+
type: "Pino",
|
|
73
|
+
options: {
|
|
74
|
+
level: (logLevel || "info").toLowerCase(),
|
|
75
|
+
pino: {
|
|
76
|
+
options: pinoOptions
|
|
77
|
+
}
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
80
|
+
: "Console"
|
|
81
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cachers } from "moleculer"
|
|
2
2
|
|
|
3
|
-
const MAX_L1_TTL =
|
|
4
|
-
const MAX_L2_TTL =
|
|
3
|
+
const MAX_L1_TTL = 600 // 10 minutes in seconds
|
|
4
|
+
const MAX_L2_TTL = 86400 // 24 hours in seconds
|
|
5
5
|
|
|
6
6
|
export default class HybridCacher extends Cachers.Base {
|
|
7
7
|
constructor(opts = {}) {
|
|
@@ -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
|
|