node-consul-service 1.0.45 → 1.0.46
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 +55 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A robust Node.js service that integrates with HashiCorp Consul for service disco
|
|
|
6
6
|
- [Features](#features)
|
|
7
7
|
- [Prerequisites](#prerequisites)
|
|
8
8
|
- [Installation](#installation)
|
|
9
|
-
- [
|
|
9
|
+
- [Initialization](#initialization)
|
|
10
10
|
- [API Documentation](#api-documentation)
|
|
11
11
|
- [Examples](#examples)
|
|
12
12
|
- [Contributing](#contributing)
|
|
@@ -35,16 +35,62 @@ npm install node-consul-service
|
|
|
35
35
|
yarn add node-consul-service
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
##
|
|
38
|
+
## Initialization
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
### Service Initialization
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
Before using any functions from the library, you must initialize the client first. You can initialize the client by passing configuration options:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
const { initClient } = require('node-consul-service');
|
|
46
|
+
|
|
47
|
+
await initClient({
|
|
48
|
+
host: 'localhost',
|
|
49
|
+
port: 8500,
|
|
50
|
+
secure: false,
|
|
51
|
+
token: 'your-token', // Optional
|
|
52
|
+
datacenter: 'dc1', // Optional
|
|
53
|
+
retryAttempts: 3, // Number of connection retry attempts
|
|
54
|
+
retryDelay: 1000 // Delay between retries in milliseconds
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Initialization Features
|
|
59
|
+
|
|
60
|
+
- **Automatic Retry**: Attempts to connect multiple times on failure
|
|
61
|
+
- **Connection Verification**: Verifies successful connection before proceeding
|
|
62
|
+
- **State Management**: Tracks initialization state to prevent multiple initializations
|
|
63
|
+
- **Error Handling**: Clear and helpful error messages
|
|
64
|
+
|
|
65
|
+
### Complete Usage Example
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const { initClient, registerService } = require('node-consul-service');
|
|
69
|
+
|
|
70
|
+
async function startService() {
|
|
71
|
+
try {
|
|
72
|
+
// Initialize client
|
|
73
|
+
await initClient({
|
|
74
|
+
host: 'localhost',
|
|
75
|
+
port: 8500,
|
|
76
|
+
retryAttempts: 3
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Register service
|
|
80
|
+
await registerService({
|
|
81
|
+
name: 'my-service',
|
|
82
|
+
id: 'my-service-1',
|
|
83
|
+
port: 3000
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
console.log('✅ Service started successfully');
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('❌ Failed to start service:', error);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
startService();
|
|
48
94
|
```
|
|
49
95
|
|
|
50
96
|
## API Documentation
|