node-consul-service 1.0.8 → 1.0.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/README.md +35 -79
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
# Node Consul Service
|
|
1
|
+
# Node Consul Service
|
|
2
2
|
|
|
3
|
-
[English](#english) | [العربية](#arabic)
|
|
4
|
-
|
|
5
|
-
## English
|
|
6
|
-
|
|
7
|
-
### Overview
|
|
8
3
|
A Node.js service that integrates with HashiCorp Consul for service discovery and configuration management. This service provides a robust solution for managing distributed systems and microservices architecture.
|
|
9
4
|
|
|
10
5
|
### Features
|
|
@@ -50,12 +45,40 @@ npm start
|
|
|
50
45
|
npm test
|
|
51
46
|
```
|
|
52
47
|
|
|
53
|
-
###
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
### Function Usage
|
|
49
|
+
Here are the main functions available in the service:
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
// Service Registration
|
|
53
|
+
const service = new ConsulService({
|
|
54
|
+
name: 'my-service',
|
|
55
|
+
port: 3000
|
|
56
|
+
});
|
|
57
|
+
await service.register();
|
|
58
|
+
|
|
59
|
+
// Service Discovery
|
|
60
|
+
const services = await service.discover('service-name');
|
|
61
|
+
|
|
62
|
+
// Key-Value Operations
|
|
63
|
+
await service.setKey('config/key', 'value');
|
|
64
|
+
const value = await service.getKey('config/key');
|
|
65
|
+
|
|
66
|
+
// Health Check
|
|
67
|
+
await service.checkHealth();
|
|
68
|
+
|
|
69
|
+
// Distributed Lock
|
|
70
|
+
const lock = await service.acquireLock('resource-name');
|
|
71
|
+
if (lock) {
|
|
72
|
+
// Perform locked operations
|
|
73
|
+
await service.releaseLock('resource-name');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Leader Election
|
|
77
|
+
await service.startLeaderElection('election-key');
|
|
78
|
+
service.on('leader', () => {
|
|
79
|
+
// Handle leader election
|
|
80
|
+
});
|
|
81
|
+
```
|
|
59
82
|
|
|
60
83
|
### Contributing
|
|
61
84
|
1. Fork the repository
|
|
@@ -66,70 +89,3 @@ The service exposes the following endpoints:
|
|
|
66
89
|
|
|
67
90
|
### License
|
|
68
91
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Arabic
|
|
73
|
-
|
|
74
|
-
### نظرة عامة
|
|
75
|
-
خدمة Node.js تتكامل مع HashiCorp Consul لاكتشاف الخدمات وإدارة التكوين. توفر هذه الخدمة حلاً قوياً لإدارة الأنظمة الموزعة وهندسة الخدمات المصغرة.
|
|
76
|
-
|
|
77
|
-
### المميزات
|
|
78
|
-
- تسجيل واكتشاف الخدمات
|
|
79
|
-
- فحص الصحة
|
|
80
|
-
- تكامل مع مخزن القيم المفتاحية
|
|
81
|
-
- إدارة التكوين
|
|
82
|
-
- القفل الموزع
|
|
83
|
-
- انتخاب القائد
|
|
84
|
-
|
|
85
|
-
### المتطلبات الأساسية
|
|
86
|
-
- Node.js (الإصدار 14 أو أحدث)
|
|
87
|
-
- خادم Consul
|
|
88
|
-
- npm أو yarn
|
|
89
|
-
|
|
90
|
-
### التثبيت
|
|
91
|
-
```bash
|
|
92
|
-
# استنساخ المستودع
|
|
93
|
-
git clone https://github.com/your-username/node-consul-service.git
|
|
94
|
-
|
|
95
|
-
# الانتقال إلى مجلد المشروع
|
|
96
|
-
cd node-consul-service
|
|
97
|
-
|
|
98
|
-
# تثبيت التبعيات
|
|
99
|
-
npm install
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### التكوين
|
|
103
|
-
قم بإنشاء ملف `.env` في المجلد الرئيسي مع المتغيرات التالية:
|
|
104
|
-
```env
|
|
105
|
-
CONSUL_HOST=localhost
|
|
106
|
-
CONSUL_PORT=8500
|
|
107
|
-
SERVICE_NAME=my-service
|
|
108
|
-
SERVICE_PORT=3000
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### الاستخدام
|
|
112
|
-
```bash
|
|
113
|
-
# تشغيل الخدمة
|
|
114
|
-
npm start
|
|
115
|
-
|
|
116
|
-
# تشغيل الاختبارات
|
|
117
|
-
npm test
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### توثيق API
|
|
121
|
-
تعرض الخدمة النقاط النهائية التالية:
|
|
122
|
-
- `GET /health` - نقطة نهاية فحص الصحة
|
|
123
|
-
- `GET /services` - قائمة الخدمات المسجلة
|
|
124
|
-
- `POST /register` - تسجيل خدمة جديدة
|
|
125
|
-
- `DELETE /deregister` - إلغاء تسجيل خدمة
|
|
126
|
-
|
|
127
|
-
### المساهمة
|
|
128
|
-
1. قم بعمل fork للمستودع
|
|
129
|
-
2. أنشئ فرع الميزة الخاص بك (`git checkout -b feature/amazing-feature`)
|
|
130
|
-
3. قم بعمل commit للتغييرات (`git commit -m 'Add some amazing feature'`)
|
|
131
|
-
4. ادفع إلى الفرع (`git push origin feature/amazing-feature`)
|
|
132
|
-
5. افتح طلب سحب (Pull Request)
|
|
133
|
-
|
|
134
|
-
### الترخيص
|
|
135
|
-
هذا المشروع مرخص تحت رخصة MIT - راجع ملف [LICENSE](LICENSE) للتفاصيل.
|