Consul 注册服务和健康检查
标签(空格分隔): go
注册服务文档:https://developer.hashicorp.com/consul/api-docs/agent/service#register-service
健康检查文档:https://developer.hashicorp.com/consul/docs/services/usage/checks
注册服务[API方式]
URL:http://127.0.0.1:8500/v1/agent/service/register
Body:
{
"ID": "user-service",
"Name": "user-service",
"Tags": ["user", "service", ""],
"Address": "127.0.0.1",
"Port": 9991
}
注册服务 check:http
URL:http://127.0.0.1:8500/v1/agent/service/register?replace-existing-checks=true
Header:Content-type:application/json
Body:`{
"ID": "user-web",
"Name": "user-web",
"Tags": ["user", "web", "gin"],
"Address": "127.0.0.1",
"Port": 9999,
// 健康检查
"Check": {
"http":"http://127.0.0.1:9999/health", // 健康检查的路径
"Interval": "5s", // 间隔5秒
"Timeout": "5s"
},
}`
注册服务:check:grpc
grpc健康检查文档:https://github.com/grpc/grpc/blob/master/doc/health-checking.md
consul-grpc健康检查文档:https://developer.hashicorp.com/consul/docs/services/usage/checks#grpc-checks
1. GRPC服务注册健康检查:
// 注册服务健康检查
// "google.golang.org/grpc/health"
// "google.golang.org/grpc/health/grpc_health_v1"
grpc_health_v1.RegisterHealthServer(s, health.NewServer())
2. Consul注册服务
URL:http://127.0.0.1:8500/v1/agent/service/register?replace-existing-checks=true
Body:{
"ID": "user-service",
"Name": "user-service",
"Tags": ["user", "service", "grpc"],
"Address": "127.0.0.1",
"Port": 9991,
"Check": {
"GRPC":"127.0.0.1:9991",
"GRPCUseTLS":false,
"Interval": "5s",
"Timeout": "5s"
}
}
验证
访问:http://127.0.0.1:8500/ui/dc1/services
标签:127.0,service,grpc,Consul,0.1,user,注册,健康检查 From: https://www.cnblogs.com/yanweifeng/p/17514381.html