Class HealthCheckService
- All Implemented Interfaces:
Unwrappable
,HttpService
,Service<HttpRequest,
,HttpResponse> TransientHttpService
,TransientService<HttpRequest,
HttpResponse>
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.
Long-polling support
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>
- e.g.
Prefer: wait=60
- e.g.
To 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.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic HealthCheckServiceBuilder
builder()
Returns a new builder which builds a newHealthCheckService
.static HealthCheckService
of
(HealthChecker... healthCheckers) Returns a newly createdHealthCheckService
with the specifiedHealthChecker
s.static HealthCheckService
of
(Iterable<? extends HealthChecker> healthCheckers) Returns a newly createdHealthCheckService
with the specifiedHealthChecker
s.serve
(ServiceRequestContext ctx, HttpRequest req) Serves an incomingRequest
.void
Invoked when this service has been added to aServer
with the specified configuration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.server.HttpService
decorate, decorate, exchangeType
Methods inherited from interface com.linecorp.armeria.server.Service
as, shouldCachePath, unwrap
-
Method Details
-
of
Returns a newly createdHealthCheckService
with the specifiedHealthChecker
s. -
of
Returns a newly createdHealthCheckService
with the specifiedHealthChecker
s. -
builder
Returns a new builder which builds a newHealthCheckService
. -
serviceAdded
Description copied from interface:Service
Invoked when this service has been added to aServer
with the specified configuration. Please note that this method can be invoked more than once if this service has been added more than once.- Specified by:
serviceAdded
in interfaceService<HttpRequest,
HttpResponse> - Throws:
Exception
-
serve
Description copied from interface:Service
Serves an incomingRequest
.- Specified by:
serve
in interfaceHttpService
- Specified by:
serve
in interfaceService<HttpRequest,
HttpResponse> - Parameters:
ctx
- the context of the receivedRequest
req
- the receivedRequest
- Returns:
- the
Response
- Throws:
Exception
-
transientServiceOptions
Description copied from interface:TransientService
Returns theSet
ofTransientServiceOption
s that are enabled for thisTransientService
. This returnsFlags.transientServiceOptions()
if you didn't specify anyTransientServiceOption
s usingTransientServiceBuilder.transientServiceOptions(TransientServiceOption...)
when you create thisTransientService
.- Specified by:
transientServiceOptions
in interfaceTransientService<HttpRequest,
HttpResponse>
-