by BehindJava

How to configure Spring Cloud Bus and Spring Boot Actuator on Spring Cloud Config Server in Spring Boot

Home » microservices » How to configure Spring Cloud Bus and Spring Boot Actuator on Spring Cloud Config Server in Spring Boot

In this tutorial we are going to learn about configuring the Spring Cloud Bus and Spring Boot Actuator on Spring Cloud Config Server using Spring Boot.

In the previous tutorial we confifured Spring Cloud Config Server,to configure the Spring Cloud Bus and Spring Boot Actuator we are going to adda couple of new dependencies to our Spring Cloud Config Server project to support the requirement.

Go to pom.xml in the Spring Cloud Config Server and add the dependencies mentioned below i.e., Spring Cloud Bus and Spring Boot Actuator.

Spring Boot Actuator helps us to monitor, manage our application and also check health status of each of our micro services.

<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-bus-amqp</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

Add the Spring Cloud Bus dependency to the other micro services that will need to have a Spring Cloud Bus Support and enables the micro service to refresh its application configuration data dynamically.

After we update the configuration properties in our remote repository, we need to tell Spring Cloud Bus that its time to broadcast the configuration changes to all the micro services that have subscribed to this update.

title

The way we can achieve this is by sending the HTTP POST request to an Actuator endpoint called BUS REFRESH and this is the reason why we added the Actuator dependency to our Spring Cloud Config Server project.

The HTTP Post request will make the Spring Cloud Config Server to load up new configuration properties from a remote git repository and also makes the Spring Cloud Bus to broadcast these updates to all the subscribed micro services.

To understand the above statement more technically, Spring Cloud Bus refresh end point helps us to clear the refresh code cache and rebind the configuration properties in our micro services.

To enable bus refresh URL end point for our Spring Cloud Config Server we need to add the below configuration under src/main/resources in the application.properties so that we can send the HTTP POST request to this web service endpoint and trigger the bus refresh of our application.

management.endpoints.web.exposure.include=busrefresh