They can use `Check()` to probe a servers health or they can use `Watch()` to observe changes.
In most cases, clients do not need to directly check backend servers.
-Instead, they can do this transparently when a `healthCheckConfig` is specified in the [service config](https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md#service-config-changes).
-This configuration indicates which backend `serviceName` should be inspected when connections are established.
+Instead, they can do this transparently when a `healthCheckConfig` is specified in the [service config](https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md#service-config-changes) and the [health package](https://pkg.go.dev/google.golang.org/grpc/health) is imported.
+The `serviceName` in `healthCheckConfig` will be used in the health check when connections are established.
An empty string (`""`) typically indicates the overall health of a server should be reported.
```go
// import grpc/health to enable transparent client side checking
import _ "google.golang.org/grpc/health"
-// set up appropriate service config
serviceConfig := grpc.WithDefaultServiceConfig(`{
"loadBalancingPolicy": "round_robin",
"healthCheckConfig": {
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pb "google.golang.org/grpc/examples/features/proto/echo"
- _ "google.golang.org/grpc/health"
+ _ "google.golang.org/grpc/health" // REQUIRED to enable health checks
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"
)
-var serviceConfig = `{
+const serviceConfig = `{
"loadBalancingPolicy": "round_robin",
"healthCheckConfig": {
"serviceName": ""
options := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
- grpc.WithBlock(),
grpc.WithResolvers(r),
+ // google.golang.org/grpc/health must also be imported
grpc.WithDefaultServiceConfig(serviceConfig),
}