1.安装consul :
brew install consul
2.如何启动consul
consul agent -dev
3.客户端这边注册信息:
func ConsulInit(){
//初始化consul配置
consulConfig := api.DefaultConfig()
//获取consul操作对象
registry,_ := api.NewClient(consulConfig)
//注册服务,服务的常规配置
registerService := api.AgentServiceRegistration{
ID:"1",
Tags:[]string{"encodeServer"},
Name:"encodeService",
Port:9093,
Address:"127.0.0.1",
Check:&api.AgentServiceCheck{
TCP:"127.0.0.1:9093",
Timeout:"5s",
Interval:"5s",
},
}
//注册服务到consul上
registry.Agent().ServiceRegister(®isterService)
}