How to check if a remote REST service is up using Spring?

Viewed 1642

I have a small REST application built using SpringBoot. I use a Feign Client to make requests to a similar application.

What I am trying to figure out is how to check if the application that the feign is making requests to is up. There is a path (api/online) that returns a 200 OK if the server is up. What I tried to do is make a GET request that returns a ResponseEntity and check its status code. But when the server is down I don't get any response and instead an Exception is thrown.

Is there an elegant way to do this?

3 Answers

I think, to handle Exceptions gracefully you may use circutebreaker with fallback. Take a look at this article

Actuator is not a option, because if app goes down, actuator would not work as well.

Also take a look at discovery service like Eurika - so before requesting something, you feign client would check if service is up and running through discovery service

So I will leave here my own solution, even though it feels a little bit primitive. What I did, in the end, was a simple try and catch where I checked that the request isn't throwing an exception, if it did I returned false, else, I returned true. I wasn't able to solve it another way, feel free to come with other options.

Related