samanbayaka 0.0.19 → 0.0.21
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 +166 -26
- package/commit-hash.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,23 @@ This project is a modular, production-ready microservices framework built with M
|
|
|
9
9
|
[](https://www.npmjs.com/package/samanbayaka)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
- [Table of contents](#table-of-contents)
|
|
13
|
+
- [Features](#features)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Prerequisites](#prerequisites)
|
|
16
|
+
- [Documentations](#documentations)
|
|
17
|
+
- [Errors](#errors)
|
|
18
|
+
- [getConfig](#getConfig)
|
|
19
|
+
- [loadDemo](#loadDemo)
|
|
20
|
+
- [loadGatewayService](#loadGatewayService)
|
|
21
|
+
- [loadFeatureService](#loadFeatureService)
|
|
22
|
+
- [auxBrokerService](#auxBrokerService)
|
|
23
|
+
- [Usage](#usage)
|
|
24
|
+
- [Demo](#Demo)
|
|
25
|
+
- [Dockers](#dockers)
|
|
26
|
+
- [Etcd](#etcd)
|
|
27
|
+
|
|
28
|
+
## Features
|
|
13
29
|
|
|
14
30
|
- Moleculer-based microservices architecture
|
|
15
31
|
- NATS transporter for high-performance messaging
|
|
@@ -23,12 +39,8 @@ This project is a modular, production-ready microservices framework built with M
|
|
|
23
39
|
- Config-driven initialization
|
|
24
40
|
- Metrics and Log shipping for Grafana
|
|
25
41
|
|
|
26
|
-
# Documentation
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
* [Etcd](https://gitlab.com/dalal.suvendu/samanbayaka/-/blob/main/docs/dockers/etcd.md?ref_type=heads)
|
|
30
|
-
|
|
31
|
-
# Installation
|
|
43
|
+
## Installation
|
|
32
44
|
|
|
33
45
|
```bash
|
|
34
46
|
pnpm install samanbayaka
|
|
@@ -37,16 +49,16 @@ Once the package is installed, you can import the library using import or requir
|
|
|
37
49
|
```bash
|
|
38
50
|
import sbk from "samanbayaka"
|
|
39
51
|
```
|
|
40
|
-
|
|
52
|
+
## Prerequisites
|
|
41
53
|
It is assumed that NATS, Redpanda, Redis, and Etcd are installed and properly configured. All services should be discoverable through the /etc/hosts file.
|
|
42
|
-
|
|
54
|
+
### Minimum required Node.js version: >= 22.x.x
|
|
43
55
|
```bash
|
|
44
56
|
node -v
|
|
45
57
|
nvm use 22
|
|
46
58
|
```
|
|
47
59
|
Additionally, OpenObserve is used to view logs and telemetry.
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
### Environment variables
|
|
50
62
|
To configure all required environment variables, create a Bash file:
|
|
51
63
|
```bash
|
|
52
64
|
source /etc/profile.d/sbk.sh
|
|
@@ -80,14 +92,14 @@ Optionally, you may verify the set environment variables.
|
|
|
80
92
|
```bash
|
|
81
93
|
echo $SBK_PORT
|
|
82
94
|
```
|
|
83
|
-
|
|
95
|
+
### Configuration files
|
|
84
96
|
Create a directory to store the configuration files, then copy all configuration files from the current project path into this directory and update them as needed. Before copying, ensure that your current working directory is the project directory.
|
|
85
97
|
```bash
|
|
86
98
|
pwd
|
|
87
99
|
sudo mkdir -p /usr/local/etc/<your_folder>
|
|
88
100
|
sudo cp config/*.* /usr/local/etc/<your_folder>
|
|
89
101
|
```
|
|
90
|
-
|
|
102
|
+
### Log files
|
|
91
103
|
For production, it is recommended to create a new directory named "samanbayaka" under /var/log to store logs.
|
|
92
104
|
```bash
|
|
93
105
|
sudo mkdir -p /var/log/samanbayaka
|
|
@@ -98,7 +110,7 @@ Empty your log files if they become very large, as follows:
|
|
|
98
110
|
```bash
|
|
99
111
|
truncate -s 0 /var/log/samanbayaka/sbk-*.log
|
|
100
112
|
```
|
|
101
|
-
|
|
113
|
+
### Setup logrotate (optional)
|
|
102
114
|
Create config file:
|
|
103
115
|
```bash
|
|
104
116
|
sudo nano /etc/logrotate.d/sbk
|
|
@@ -117,27 +129,27 @@ Paste this:
|
|
|
117
129
|
}
|
|
118
130
|
```
|
|
119
131
|
|
|
120
|
-
##
|
|
132
|
+
## Documentations
|
|
121
133
|
|
|
122
|
-
###
|
|
134
|
+
### Errors
|
|
123
135
|
|
|
124
136
|
`sbk.Errors` exposes the Moleculer `Errors` object.
|
|
125
137
|
|
|
126
|
-
###
|
|
138
|
+
### getConfig
|
|
127
139
|
|
|
128
140
|
`sbk.getConfig` is a function that returns a configuration object from a specified file name.
|
|
129
141
|
|
|
130
142
|
The file is loaded from the configuration directory defined by the environment variable.
|
|
131
143
|
|
|
132
|
-
###
|
|
144
|
+
### loadDemo
|
|
133
145
|
|
|
134
146
|
`sbk.loadDemo` is an asynchronous function that creates a demo service to help understand the project.
|
|
135
147
|
|
|
136
|
-
###
|
|
148
|
+
### loadGatewayService
|
|
137
149
|
|
|
138
150
|
`sbk.loadGatewayService` is an asynchronous function that creates a gateway service to expose REST APIs.
|
|
139
151
|
|
|
140
|
-
###
|
|
152
|
+
### loadFeatureService
|
|
141
153
|
|
|
142
154
|
`sbk.loadFeatureService` is an asynchronous function that creates a feature service.
|
|
143
155
|
|
|
@@ -169,7 +181,7 @@ Example:
|
|
|
169
181
|
```
|
|
170
182
|
|
|
171
183
|
|
|
172
|
-
###
|
|
184
|
+
### auxBrokerService
|
|
173
185
|
|
|
174
186
|
`sbk.auxBrokerService` is a function used to initialize and manage message brokers such as Kafka, MQTT, and RabbitMQ.
|
|
175
187
|
|
|
@@ -248,8 +260,8 @@ Example:
|
|
|
248
260
|
}
|
|
249
261
|
```
|
|
250
262
|
|
|
251
|
-
|
|
252
|
-
|
|
263
|
+
## Usage
|
|
264
|
+
### Create gateway service
|
|
253
265
|
The Gateway is a critical service that exposes all endpoints as REST APIs. At least one Gateway service must be running to make the REST APIs accessible.
|
|
254
266
|
```bash
|
|
255
267
|
mkdir gateway
|
|
@@ -265,7 +277,7 @@ import sbk from "samanbayaka"
|
|
|
265
277
|
await sbk.loadGatewayService()
|
|
266
278
|
```
|
|
267
279
|
---
|
|
268
|
-
|
|
280
|
+
### Create feature services
|
|
269
281
|
```bash
|
|
270
282
|
mkdir <your_service_name>
|
|
271
283
|
cd <your_service_name>
|
|
@@ -324,7 +336,7 @@ await sbk.loadFeatureService({
|
|
|
324
336
|
|
|
325
337
|
```
|
|
326
338
|
---
|
|
327
|
-
|
|
339
|
+
### Create auxaliary broker services
|
|
328
340
|
##### for producer
|
|
329
341
|
```bash
|
|
330
342
|
mkdir <your_service_name>-<type>-<topic>
|
|
@@ -365,7 +377,7 @@ If you do not expose the service as a REST API and run it as a private/internal
|
|
|
365
377
|
rest: false
|
|
366
378
|
```
|
|
367
379
|
|
|
368
|
-
|
|
380
|
+
#### for consumer
|
|
369
381
|
```bash
|
|
370
382
|
mkdir <your_service_name>-<type>-<topic>-<group>
|
|
371
383
|
cd <your_service_name>-<type>-<topic>-<group>
|
|
@@ -403,7 +415,7 @@ The `interMessageDelayMs` option introduces a delay between two consecutive mess
|
|
|
403
415
|
|
|
404
416
|
---
|
|
405
417
|
|
|
406
|
-
|
|
418
|
+
### Run the services
|
|
407
419
|
|
|
408
420
|
* development/testing
|
|
409
421
|
```bash
|
|
@@ -420,7 +432,7 @@ cd <your_path>/hello
|
|
|
420
432
|
node index.mjs >> /var/log/samanbayaka/sbk-${HOSTNAME}-$$.log 2>&1
|
|
421
433
|
```
|
|
422
434
|
|
|
423
|
-
|
|
435
|
+
## Demo
|
|
424
436
|
You can also run the demo service to better understand how microservices work in the Moleculer ecosystem and how REST APIs are exposed.
|
|
425
437
|
```bash
|
|
426
438
|
mkdir demo
|
|
@@ -439,6 +451,134 @@ Run the service, demo
|
|
|
439
451
|
node demo.mjs
|
|
440
452
|
```
|
|
441
453
|
|
|
454
|
+
## Dockers
|
|
455
|
+
|
|
456
|
+
### Etcd
|
|
457
|
+
To manage configurations centrally, use the docker-compose.yml file to run Etcd.
|
|
458
|
+
```bash
|
|
459
|
+
mkdir -p etcd
|
|
460
|
+
cd etcd
|
|
461
|
+
touch docker-compose.yml
|
|
462
|
+
export ETCD_ROOT_PW=<your_root_pass>
|
|
463
|
+
export ETCD_CONFIG_ADMIN_PW=<your_config_admin_pass>
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Open `docker-compose.yml` and paste the following:
|
|
467
|
+
```yml
|
|
468
|
+
services:
|
|
469
|
+
etcd:
|
|
470
|
+
image: quay.io/coreos/etcd:v3.5.5
|
|
471
|
+
container_name: sbk-etcd
|
|
472
|
+
|
|
473
|
+
ports:
|
|
474
|
+
- "<your_api_port>:2379"
|
|
475
|
+
- "<your_cluster_port>:2380"
|
|
476
|
+
|
|
477
|
+
volumes:
|
|
478
|
+
- /usr/local/etc/samanbayaka:/etcd-data
|
|
479
|
+
|
|
480
|
+
command:
|
|
481
|
+
- /usr/local/bin/etcd
|
|
482
|
+
- --name=etcd
|
|
483
|
+
- --data-dir=/etcd-data
|
|
484
|
+
- --listen-client-urls=http://0.0.0.0:2379
|
|
485
|
+
- --advertise-client-urls=http://etcd:2379
|
|
486
|
+
- --listen-peer-urls=http://0.0.0.0:2380
|
|
487
|
+
- --initial-advertise-peer-urls=http://etcd:2380
|
|
488
|
+
- --initial-cluster=etcd=http://etcd:2380
|
|
489
|
+
- --initial-cluster-state=new
|
|
490
|
+
|
|
491
|
+
restart: unless-stopped
|
|
492
|
+
|
|
493
|
+
etcd-init:
|
|
494
|
+
image: quay.io/coreos/etcd:v3.5.5
|
|
495
|
+
depends_on:
|
|
496
|
+
- etcd
|
|
497
|
+
|
|
498
|
+
volumes:
|
|
499
|
+
- /usr/local/etc/samanbayaka:/etcd-data
|
|
500
|
+
|
|
501
|
+
environment:
|
|
502
|
+
- ETCDCTL_API=3
|
|
503
|
+
|
|
504
|
+
entrypoint:
|
|
505
|
+
- /bin/sh
|
|
506
|
+
- -c
|
|
507
|
+
|
|
508
|
+
command:
|
|
509
|
+
- |
|
|
510
|
+
set -e
|
|
511
|
+
|
|
512
|
+
echo "waiting for etcd..."
|
|
513
|
+
|
|
514
|
+
for i in $(seq 1 30); do
|
|
515
|
+
etcdctl --endpoints=http://etcd:2379 endpoint health && break
|
|
516
|
+
echo "retry $$i..."
|
|
517
|
+
sleep 2
|
|
518
|
+
done
|
|
519
|
+
|
|
520
|
+
echo "etcd initialized"
|
|
521
|
+
|
|
522
|
+
echo "Creating the root role"
|
|
523
|
+
etcdctl --endpoints=http://etcd:2379 role add root || true
|
|
524
|
+
|
|
525
|
+
echo "Creating the root user"
|
|
526
|
+
etcdctl --endpoints=http://etcd:2379 user add root:${ETCD_ROOT_PW} || true
|
|
527
|
+
|
|
528
|
+
echo "Granting the root role to the root user"
|
|
529
|
+
etcdctl --endpoints=http://etcd:2379 user grant-role root root
|
|
530
|
+
|
|
531
|
+
echo "Enable authentication"
|
|
532
|
+
etcdctl --endpoints=http://etcd:2379 auth enable || true
|
|
533
|
+
|
|
534
|
+
# -------------------------------------------------------
|
|
535
|
+
|
|
536
|
+
echo "Creating admin role"
|
|
537
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add admin
|
|
538
|
+
|
|
539
|
+
echo "Granting broad permissions"
|
|
540
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true admin readwrite /
|
|
541
|
+
|
|
542
|
+
echo "Creating configadmin user"
|
|
543
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add configadmin:${ETCD_CONFIG_ADMIN_PW}
|
|
544
|
+
|
|
545
|
+
echo "Assign role"
|
|
546
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role configadmin admin
|
|
547
|
+
|
|
548
|
+
# ---------------------------------------------------------
|
|
549
|
+
|
|
550
|
+
echo "Creating Roles and Granting"
|
|
551
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role add gateway
|
|
552
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true gateway read /config/yaml/nats
|
|
553
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true gateway read /config/yaml/auth
|
|
554
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true gateway read /config/yaml/catch
|
|
555
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} role grant-permission --prefix=true gateway read /config/yaml/telemetry
|
|
556
|
+
|
|
557
|
+
# ---------------------------------------------------------
|
|
558
|
+
|
|
559
|
+
echo "Creating User and Assign Role"
|
|
560
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user add <your_user>:<your_pass>
|
|
561
|
+
etcdctl --endpoints=http://etcd:2379 --user=root:${ETCD_ROOT_PW} user grant-role apigtwy gateway
|
|
562
|
+
|
|
563
|
+
# ---------------------------------------------------------
|
|
564
|
+
|
|
565
|
+
etcdctl --endpoints=http://etcd:2379 --user=configadmin:${ETCD_CONFIG_ADMIN_PW} put /config/yaml/nats "$(cat /etcd-data/nats.yml)" || true
|
|
566
|
+
|
|
567
|
+
#etcdctl --endpoints=http://etcd:2379 --user=<your_user>:<your_pass> get /config/yaml/nats
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
echo "etcd initialization completed"
|
|
571
|
+
```
|
|
572
|
+
Optionally verify:
|
|
573
|
+
```bash
|
|
574
|
+
docker ps | grep 'sbk-etcd'
|
|
575
|
+
```
|
|
576
|
+
Optionally check health:
|
|
577
|
+
```bash
|
|
578
|
+
docker exec -it sbk-etcd etcdctl --endpoints=http://etcd:2379 endpoint health
|
|
579
|
+
```
|
|
580
|
+
---
|
|
581
|
+
|
|
442
582
|
<p align="center" style="margin-top: 100px;">
|
|
443
583
|
<img src="https://moleculer.services/images/banner.png" alt="Moleculer Logo" width="600">
|
|
444
584
|
</p>
|
package/commit-hash.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const COMMIT_HASH = '
|
|
1
|
+
export const COMMIT_HASH = '85a1def';
|