https://github.com/kuangshp/node-consul
node实现consul服务发现
https://github.com/kuangshp/node-consul
Last synced: 8 months ago
JSON representation
node实现consul服务发现
- Host: GitHub
- URL: https://github.com/kuangshp/node-consul
- Owner: kuangshp
- Created: 2021-10-30T06:43:31.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-30T07:59:55.000Z (almost 4 years ago)
- Last Synced: 2025-02-18T10:42:07.638Z (8 months ago)
- Language: JavaScript
- Size: 55.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Node中使用consul实现服务发现
## 一、使用方式
* 1、安装依赖包
```properties
npm install node-consul
```* 2、使用
```typescript
import NodeConsul, { computerIPAddress } from '../src';
const nodeConsul = new NodeConsul('localhost:8500');
// 注册一个服务
nodeConsul.registerService(6000, 'test-consul2', 'test-consul3', ['test1', 'test2'], {
HTTP: `http://${computerIPAddress()}:3000/health`,
Timeout: '5s',
Interval: '5s',
DeregisterCriticalServiceAfter: '10s',
});
// 删除服务
nodeConsul.deregisterServiceById('test-consul3');
// 查询服务
(async () => {
const list = await nodeConsul.findService('node-consul');
console.log(list);
})();
```