先上个代码片段开胃
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服务:
package必须写成grpc.health.v1
... consul源代码里写死了调用grpc的health check
HealthCheckRequest中的service字段并不是AgentServiceRegistrationn
的Name, 更不是AgentServiceCheck
中的Name。看了下源代码才发现,原来是在写GRPC参数时,在endpoint后加个/<service>