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 HealthCheckServiceBuilderbuilder()Returns a new builder which builds a newHealthCheckService.static HealthCheckServiceof(HealthChecker... healthCheckers) Returns a newly createdHealthCheckServicewith the specifiedHealthCheckers.static HealthCheckServiceof(Iterable<? extends HealthChecker> healthCheckers) Returns a newly createdHealthCheckServicewith the specifiedHealthCheckers.serve(ServiceRequestContext ctx, HttpRequest req) Serves an incomingRequest.voidInvoked when this service has been added to aServerwith the specified configuration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.linecorp.armeria.server.HttpService
decorate, decorate, exchangeType, optionsMethods inherited from interface com.linecorp.armeria.server.Service
as, shouldCachePath, unwrapMethods inherited from interface com.linecorp.armeria.common.util.Unwrappable
equalsIgnoreWrapper, unwrapAll
-
Method Details
-
of
Returns a newly createdHealthCheckServicewith the specifiedHealthCheckers. -
of
Returns a newly createdHealthCheckServicewith the specifiedHealthCheckers. -
builder
Returns a new builder which builds a newHealthCheckService. -
serviceAdded
Description copied from interface:ServiceInvoked when this service has been added to aServerwith 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:
serviceAddedin interfaceService<HttpRequest,HttpResponse> - Throws:
Exception
-
serve
Description copied from interface:ServiceServes an incomingRequest.- Specified by:
servein interfaceHttpService- Specified by:
servein interfaceService<HttpRequest,HttpResponse> - Parameters:
ctx- the context of the receivedRequestreq- the receivedRequest- Returns:
- the
Response - Throws:
Exception
-
transientServiceOptions
Description copied from interface:TransientServiceReturns theSetofTransientServiceOptions that are enabled for thisTransientService. This returnsFlags.transientServiceOptions()if you didn't specify anyTransientServiceOptions usingTransientServiceBuilder.transientServiceOptions(TransientServiceOption...)when you create thisTransientService.- Specified by:
transientServiceOptionsin interfaceTransientService<HttpRequest,HttpResponse>
-