first commit
This commit is contained in:
31
app/src/utils/consul.ts
Normal file
31
app/src/utils/consul.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import Consul, { ConsulOptions } from "consul";
|
||||
import Config from "../config";
|
||||
|
||||
export class ConsulConf {
|
||||
consulInstance!: Consul.Consul;
|
||||
|
||||
constructor(option: ConsulOptions) {
|
||||
this.consulInstance = new Consul(option);
|
||||
|
||||
// 批量注册各个服务
|
||||
Config.servicesList.forEach(async v => {
|
||||
await this.register(v)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务注册
|
||||
*/
|
||||
async register(option: Consul.Agent.Service.RegisterOptions) {
|
||||
let res = await this.consulInstance.agent.service.register(option);
|
||||
console.log("res: === :", res);
|
||||
}
|
||||
|
||||
async list() {
|
||||
return await this.consulInstance.agent.service.list();
|
||||
}
|
||||
|
||||
async deregister(id: string) {
|
||||
return await this.consulInstance.agent.service.deregister(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user