Chapter 30: Server Reflection and Health Checking
Server Reflection
Allows clients to discover available services and methods at runtime (like Swagger for REST):
// Enable reflection in C++ server:
#include <grpcpp/ext/proto_server_reflection_plugin.h>
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
// Now grpcurl can discover services without .proto files:
$ grpcurl -plaintext localhost:50051 list
$ grpcurl -plaintext localhost:50051 describe mypackage.MyService
Health Checking Protocol
// Standard health check service (grpc.health.v1.Health):
service Health {
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);
}
// Response status: UNKNOWN, SERVING, NOT_SERVING
// Used by: Kubernetes liveness/readiness probes, load balancers
Kubernetes Integration
# Pod spec with gRPC health check:
livenessProbe:
grpc:
port: 50051
initialDelaySeconds: 5
readinessProbe:
grpc:
port: 50051