Reputation: 1
in a cloud context I need to be able to find out when a spring boot vaadin service is ready for user connections. I've tried a call to /actuator/health but the service is UP well before vaadin beeing ready ... Has someone faced the same issue and found a solution ?
Just to make it clear, my issue is more at the load balanced level. I need to find a way to tell the load balancer (I'm using sticky session) that the new spawned vaadin service is ready to receive users ... this is where I've used the /actuator/health but the service is UP before vaadin is ready.
Upvotes: 0
Views: 671
Reputation: 448
Our application (deployed on AWS with an Application Load Balancer) is based on Spring Boot and Vaadin 14. We've been using a ServletFilter to instruct the load balancer to direct traffic:
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class HealthCheckFilter implements Filter {
public static final String HEALTH_CHECK_PATH = "/healthcheck";
private boolean vaadinIsInitialized = false;
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
if (request.getRequestURI().endsWith(HEALTH_CHECK_PATH) && vaadinIsInitialized) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
filterChain.doFilter(servletRequest, servletResponse);
}
}
@EventListener({ContextRefreshedEvent.class})
public void contextRefreshedEvent() {
// invoked after Spring finishes loading the application context, which is after
// Vaadin and the embedded application server has started
vaadinIsInitialized = true;
}
}
There are at least two interesting events that happen as part of the initialization of our application that could be used to indicate that the application is ready to service requests.
Upvotes: 4