grpcio_health/lib.rs
1// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.
2
3//! grpcio-health provides health check protos as well as some helper structs to make
4//! health check easily. For the detail design of health checking service, see
5//! https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
6//!
7//! ### Usage
8//!
9//! The crate provides a default implementation of `Health` service, you can use it
10//! to maintain the service states. First, you need to register it to the server builder
11//! so that it can serve health check service later.
12//! ```ignore
13//! use grpcio_health::{HealthService, create_health};
14//!
15//! let service = HealthService::default();
16//! let builder = builder.register_service(create_health(service.clone()));
17//! ```
18//! Then insert service status for query.
19//! ```ignore
20//! service.set_serving_status("", ServingStatus::Serving);
21//! ```
22//! `""` means overall health status. You can also provide specific service name.
23//!
24//! Client can either use `check` to do one time query or `watch` to observe status changes.
25//! ```ignore
26//! use grpcio_health::proto::HealthCheckRequest;
27//!
28//! let client = HealthClient::new(ch);
29//! let req = HealthCheckRequest { service: "".to_string(), ..Default::default() };
30//! let status_resp = client.check_async(&req).await.unwrap();
31//! assert_eq!(statuss_resp.status, ServingStatus::Serving);
32//! ```
33
34pub mod proto;
35mod service;
36
37pub use self::proto::{create_health, HealthClient};
38pub use self::service::HealthService;
39
40#[cfg(feature = "protobuf-codec")]
41pub use self::proto::ServingStatus;
42
43#[cfg(feature = "protobufv3-codec")]
44pub use self::proto::health_check_response::ServingStatus;