public final class HealthCheckService extends Object implements TransientHttpService
HttpService that responds with HTTP status "200 OK" if the server is healthy and can
accept requests and HTTP status "503 Service Not Available" if the server is unhealthy and cannot
accept requests. The default behavior is to respond healthy after the server is started and unhealthy
after it started to stop.
A client that sends health check requests to this service can send a long-polling request to get notified
immediately when a Server becomes healthy or unhealthy, rather than sending health check requests
periodically.
To wait until a Server becomes unhealthy, i.e. wait for the failure, send an HTTP request with
two additional headers:
If-None-Match: "healthy"Prefer: wait=<seconds>
Prefer: wait=60To wait until a Server becomes healthy, i.e. wait for the recovery, send an HTTP request with
two additional headers:
If-None-Match: "unhealthy"Prefer: wait=<seconds>The Server will wait up to the amount of seconds specified in the "Prefer" header
and respond with "200 OK", "503 Service Unavailable" or "304 Not Modified".
"304 Not Modifies" signifies that the healthiness of the Server did not change.
Once the response is received, the client is supposed to send a new long-polling request to continue
watching the healthiness of the Server.
All health check responses will contain a "armeria-lphc" header whose value is the maximum
allowed value of the "Prefer: wait=<seconds>" header. 0 means long polling has been
disabled. "lphc" stands for long-polling health check.
HealthCheckServiceBuilder| Modifier and Type | Method and Description |
|---|---|
static HealthCheckServiceBuilder |
builder()
Returns a new builder which builds a new
HealthCheckService. |
static HealthCheckService |
of(HealthChecker... healthCheckers)
Returns a newly created
HealthCheckService with the specified HealthCheckers. |
static HealthCheckService |
of(Iterable<? extends HealthChecker> healthCheckers)
Returns a newly created
HealthCheckService with the specified HealthCheckers. |
HttpResponse |
serve(ServiceRequestContext ctx,
HttpRequest req)
Serves an incoming
Request. |
void |
serviceAdded(ServiceConfig cfg)
Invoked when this service has been added to a
Server with the specified
configuration. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdecorate, decorateas, decorate, shouldCachePathpublic static HealthCheckService of(HealthChecker... healthCheckers)
HealthCheckService with the specified HealthCheckers.public static HealthCheckService of(Iterable<? extends HealthChecker> healthCheckers)
HealthCheckService with the specified HealthCheckers.public static HealthCheckServiceBuilder builder()
HealthCheckService.public void serviceAdded(ServiceConfig cfg) throws Exception
ServiceServer with the specified
configuration. Please note that this method can be invoked more than once if this service
has been added more than once.serviceAdded in interface Service<HttpRequest,HttpResponse>Exceptionpublic HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception
ServiceRequest.serve in interface HttpServiceserve in interface Service<HttpRequest,HttpResponse>ctx - the context of the received Requestreq - the received RequestResponseExceptionCopyright © 2020 LeanCloud. All rights reserved.