consul 服务注册
consul 服务和user-web服务的ip地址不能一样吗?我的健康检查没有成功
package main
import "github.com/hashicorp/consul/api"
func Register(
address string,
port int,
name string,
tags []string,
id string,
) error {
cfg := api.DefaultConfig()
cfg.Address = "10.10.10.110:8500"
client, err := api.NewClient(cfg)
if err != nil {
panic(err.Error())
}
// 生成对象的检查对象
check := &api.AgentServiceCheck{
HTTP: "http://10.10.10.110:8021/health",
Interval: "5s",
Timeout: "5s",
DeregisterCriticalServiceAfter: "10s",
}
// 生成注册对象
registration := new(api.AgentServiceRegistration)
registration.Name = name
registration.Address = address
registration.Tags = tags
registration.ID = id
registration.Port = port
registration.Check = check
err = client.Agent().ServiceRegister(registration)
if err != nil {
panic(err.Error())
}
return nil
}
func main() {
_ = Register(
"10.10.10.110",
8021,
"user-web",
[]string{"mxshop", "go++"},
"user-web",
)
}
61
收起
正在回答
2回答
可以不一样,但是你要确保你能在consul容器中能ping通
10.10.10.110
这个ip才行
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星