In spring boot microservices based application, where microservices talks to each other using RESTFul APIs. We can expose some important information about microservice such as name, version, description over some endpoints say /info and also realtime status or health over some endpoint say /health to create application dashboards, realtime alerts, track microservice updates and so on…
Good news is that both endpoints come out of the box with
Spring Boot Actuator. To enable this, just add spring-boot-starter-actuator dependency in your spring boot application.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
When you start your application after adding actuator dependency, You will see following in the startup logs that actuator exposed two endpoints i.e. /actuator/info and /actuator/health
2020-04-20 18:36:12.881 INFO [main] o.s.b.a.e.web.EndpointLinksResolver: Exposing 2 endpoint(s) beneath base path '/actuator'
We see that initially /actuator/info endpoint gives an empty JSON. We will now add some properties related to app info.
info: app: name: spring boot microservice version: 1.0.0_RELEASE description: more details about sprint boot microservice contact-support: email@example.com copyright: copyright (c) abc.com license: MIT tech-used: - name: java version: 11.x - name: spring-boot version: 2.x
That’s all we need to do to make this data available on the /actuator/info endpoint. Spring will automatically add all the properties prefixed with info to the endpoint.
/actuator/info endpoint can be used to -
- create a dashboard of microservices info
- check for version update of particular microservice and so and so forth…
By default endpoint show the current status of the running application.
/actuator/health endpoint can be used to -
- create a dashboard of microservices with realtime status
- check the heartbeat of microservice and so and so forth…