gRPC API¶
The router's API is defined in
proto/grpc_router_service.proto.
Python services and clients can use GRPCRouterClient; from other languages, generate a client
from the proto file, or explore the API of a running router with server reflection, e.g. with grpcurl.
A service written in another language has to do what GRPCRouterClient does for ACTIVE_CLIENT instances: call
PushHealthStatus regularly (well within the router's health check timeout, 5 minutes by default), and call
RegisterService again when PushHealthStatus returns NOT_FOUND. See Health checks.
syntax = "proto3";
package grpcrouter;
option java_package = "com.grpcrouter.service";
option java_multiple_files = true;
service GRPCRouterService {
// Register a service endpoint
//
// Called by a service that wants to advertise its services to clients.
// Provides a service_id which ideally should be a dot separated namespace representing
// the service but it can be anything, e.g.: org.suborg.scope1.service1
// It also has information about how clients can connect directly to the service (ie host/port)
// The service gets back a service_token which it can use to communicate with the grpc router.
// A registration replaces the entries of the same service_id, host and port that look dead
// (e.g. the same service restarted): entries that are out of service, that missed heartbeats or
// that have no health checks.
rpc RegisterService(ServiceRegistrationRequest) returns (ServiceRegistrationResponse) {}
// Deregister a service endpoint
//
// Called by a service when it exits and it no longer serves client requests.
// The service should pass its service_token which was obtained at registration.
rpc DeregisterService(ServiceDeregistrationRequest) returns (ServiceDeregistrationResponse) {}
// Get the detail of a service
//
// Returns the details of a registered service when called by a client.
// The client then can connect directly to that service.
// The client specifies the service_id which is service register for.
// When multiple services are registered for the same service_id, they are returned in a simple
// round-robin fashion.
rpc GetRegisteredService(GetRegisteredServiceRequest) returns (GetRegisteredServiceResponse) {}
// Client pushes the health status periodically
//
// This is used in the ACTIVE_CLIENT modus operandi for clients to
// push health info to the grpc router.
// Clients using this method must specify health check type ACTIVE_CLIENT
// when registering.
//
// A service that misses heartbeats for longer than the router's health check timeout,
// or that reports HEALTH_STATUS_ERROR, is taken out of service: it is no longer returned
// by GetRegisteredService. It keeps its service_token and should keep pushing (ERROR
// included) while it is out of service; it goes back in service as soon as it pushes any
// status other than HEALTH_STATUS_ERROR. A service that is out of service and pushes
// nothing for longer than the router's expiry timeout is forgotten, and gets NOT_FOUND
// until it registers again.
rpc PushHealthStatus(HealthInfoRequest) returns (HealthInfoResponse) {}
}
enum HealthCheckType {
HEALTH_CHECK_NONE = 0; // no health checks
HEALTH_CHECK_ACTIVE_CLIENT = 1; // client will push health notifications to the server
HEALTH_CHECK_PASSIVE_CLIENT = 2; // client implements the health grpc interface and server should poll/watch
}
enum HealthStatus {
HEALTH_STATUS_UNKNOWN = 0;
HEALTH_STATUS_GOOD = 1;
HEALTH_STATUS_WARNING = 2;
HEALTH_STATUS_ERROR = 3;
}
message ServiceEndpoint {
string host = 1; // hostname of the service
int32 port = 2; // port of the service
}
message ServiceMetadata {
string region = 1;
int32 slots = 2;
HealthCheckType health_check_type = 3;
}
message ServiceRegistrationRequest {
string service_id = 1; // identifier of the service that the clients will use
ServiceEndpoint endpoint = 2;
ServiceMetadata metadata = 3;
}
message ServiceRegistrationResponse {
string service_token = 1;
}
message ServiceDeregistrationRequest {
string service_id = 1;
string service_token = 2;
}
message ServiceDeregistrationResponse {
}
message ServiceHints {
string region = 1;
}
message GetRegisteredServiceRequest {
string service_id = 1;
ServiceHints hints = 2;
}
message GetRegisteredServiceResponse {
string service_id = 1;
ServiceEndpoint endpoint = 2;
}
message HealthInfoRequest {
string service_id = 1;
string service_token = 2;
HealthStatus status = 3;
string description = 4;
}
message HealthInfoResponse{
}