HealthCheckService.@Deprecated public class HttpHealthCheckService extends AbstractHttpService 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.
Subclasses can override newHealthyResponse(ServiceRequestContext) or
newUnhealthyResponse(ServiceRequestContext) if they need to customize the response.
Server server = Server.builder()
.service("/services", myService)
.service("/health", new HttpHealthCheckService())
.build();
You can also specify additional HealthCheckers at construction time. It will respond with a
unhealthy response if the HealthChecker.isHealthy() method returns false for any of them.
This can be useful when you want to stop receiving requests from a load balancer without stopping a
Server. e.g. the backend got unhealthy.
SettableHealthChecker healthChecker = new SettableHealthChecker();
Server server = Server.builder()
.service("/services", myService)
.service("/health", new HttpHealthCheckService(healthChecker))
.build();
| Constructor and Description |
|---|
HttpHealthCheckService(HealthChecker... healthCheckers)
Deprecated.
Creates a new instance.
|
HttpHealthCheckService(Iterable<? extends HealthChecker> healthCheckers)
Deprecated.
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected HttpResponse |
doGet(ServiceRequestContext ctx,
HttpRequest req)
Deprecated.
Handles a
GET request. |
protected HttpResponse |
doHead(ServiceRequestContext ctx,
HttpRequest req)
Deprecated.
Handles a
HEAD request. |
protected AggregatedHttpResponse |
newHealthyResponse(ServiceRequestContext ctx)
Deprecated.
Creates a new response which is sent when the
Server is healthy. |
protected AggregatedHttpResponse |
newUnhealthyResponse(ServiceRequestContext ctx)
Deprecated.
Creates a new response which is sent when the
Server is unhealthy. |
void |
serviceAdded(ServiceConfig cfg)
Deprecated.
Invoked when this service has been added to a
Server with the specified
configuration. |
doDelete, doDelete, doGet, doHead, doOptions, doOptions, doPatch, doPatch, doPost, doPost, doPut, doPut, doTrace, doTrace, serveclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdecorate, decorate, serveas, decorate, shouldCachePathpublic HttpHealthCheckService(HealthChecker... healthCheckers)
healthCheckers - the additional HealthCheckerspublic HttpHealthCheckService(Iterable<? extends HealthChecker> healthCheckers)
healthCheckers - the additional HealthCheckersprotected AggregatedHttpResponse newHealthyResponse(ServiceRequestContext ctx)
Server is healthy.protected AggregatedHttpResponse newUnhealthyResponse(ServiceRequestContext ctx)
Server is unhealthy.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>Exceptionprotected HttpResponse doHead(ServiceRequestContext ctx, HttpRequest req)
AbstractHttpServiceHEAD request.
This method sends a 405 Method Not Allowed response by default.doHead in class AbstractHttpServiceprotected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req)
AbstractHttpServiceGET request.
This method sends a 405 Method Not Allowed response by default.doGet in class AbstractHttpServiceCopyright © 2020 LeanCloud. All rights reserved.