[笔记] consul用grpc做健康检查注意点

为什么80%的码农都做不了架构师?>>>   hot3.png

先上个代码片段开胃

	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后加个/ https://github.com/hashicorp/consul/blob/master/agent/checks/grpc.go#L29

转载于:https://my.oschina.net/tuxpy/blog/1798913

你可能感兴趣的:([笔记] consul用grpc做健康检查注意点)