Consul 注册的信息
reg := api.AgentServiceRegistration{
ID: strconv.FormatInt(time.Now().UnixNano(), 10),
Name: name,
Address: listen,
Port: port,
Check: &api.AgentServiceCheck{
GRPC: fmt.Sprintf("%v:%v/%v", listen, port, name),
Interval: "5s",
Notes: "Consul check service health status.",
DeregisterCriticalServiceAfter: "10s",
},
}
我按照 https://www.consul.io/docs/discovery/checks 里的 grpc 检查里,写了个 proto
syntax = "proto3";
package grpc_health_v1;
option go_package = ".;grpc_health_v1";
message HealthCheckRequest {
string service = 1;
}
message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
SERVICE_UNKNOWN = 3; // Used only by the Watch method.
}
ServingStatus status = 1;
}
service Health {
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);
}
我用 BloomRPC 和自己写的 client 都能正常访问这个 Check 方法,但是注册上了 Consul 却显示失败
1
axex 2020-11-16 14:18:39 +08:00
grpc 的 health check 是不需要你实现的,grpc 的库中有 google.golang.org/grpc/health/grpc_health_v1,你直接 import 然后 RegisterHealthServer(grpcServer, health.NewServer())就行了
|
2
wunonglin OP @axex #1
我现在改了下代码引入了,但是&api.AgentServiceCheck 里的 GRPC 是要怎么填, 是 ip:port 还是 ip:port/service_name 还是 ip:port//grpc_health_v1.Health ?我都试了都不行 |
4
wunonglin OP @axex #3
grpc: addrConn.createTransport failed to connect to {127.0.0.1:8080 0 <nil>}. Err :connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:8080: connect: connection refused". Reconnecting... 提示这个,但是我自己写了一个 client 测试的话是可以连接上来的 |
5
axex 2020-11-16 15:14:12 +08:00
@wunonglin consul 和 grpc server 在同一台机器上面?不是的话 consul 是无法访问的,最好改成内网 ip 或者改用 ttl 检查
|
6
wunonglin OP |