先上个代码片段开胃
registration := &consulapi.AgentServiceRegistration{
Address: address,
Port: port,
ID: id,
Name: serviceName,
Check: &consulapi.AgentServiceCheck{
GRPC: fmt.Sprintf("%s:%d/%s", address, port, serviceName),
Interval: "3s",
},
}
err = cli.Agent().ServiceRegister(registration)
protobuf写一个Health服务: https://github.com/grpc/grpc/blob/master/doc/health-checking.md
package必须写成grpc.health.v1 ... consul源代码里写死了调用grpc的health check https://github.com/hashicorp/consul/blob/master/agent/checks/grpc.go#L65
HealthCheckRequest中的service字段并不是AgentServiceRegistrationn的Name, 更不是AgentServiceCheck中的Name。看了下源代码才发现,原来是在写GRPC参数时,在endpoint后加个/<service> https://github.com/hashicorp/consul/blob/master/agent/checks/grpc.go#L29
本文探讨了如何使用Consul进行服务注册,并通过gRPC实现健康检查。详细介绍了AgentServiceRegistration配置,以及如何设置gRPC健康检查参数,强调HealthCheckRequest中的service字段的正确使用方法。
1529

被折叠的 条评论
为什么被折叠?



