I have two instances of an app running. Is it possible for one app to check health of the other using any features of Spring framework ?
Asked
Active
Viewed 83 times
0
-
what do you mean two instances of the same app ? Can you elaborate a little more on that ? – Hary Oct 22 '18 at 07:42
2 Answers
1
Yes. You can use Health Indicator with Actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Available endpoints
/health /info /metrics /trace
it can return
{
"status" : "UP"
}
and
{
"status" : "DOWN",
"myHealthCheck" : {
"status" : "DOWN",
"Error Code" : 1
},
"diskSpace" : {
"status" : "UP",
"free" : 209047318528,
"threshold" : 10485760
}
}
Read more here https://www.baeldung.com/spring-boot-actuators

Sully
- 14,672
- 5
- 54
- 79
1
To elaborate a bit on the answer by Hitham:
Let's say app A needs to report the status of App B. For that reason it seems that A depends on B for some service?
In any case, you can implement a HealthIndicator
in A that attempts to call the service you need on B, using some benign, side-effect free operation.

Hans Westerbeek
- 5,645
- 3
- 34
- 35
-
He said 2 instances of the same App, you are stating them as two different apps – Hary Oct 22 '18 at 07:41
-
True. I guess he'd have to active those healtheck using a spring @Profile – Hans Westerbeek Oct 22 '18 at 08:07