Spring Cloud Bus

Code Dexterous
2 min readJul 23, 2020

In our project whenever we do changes in Config Service then we have to restart all applications to load the changes in configurations.

This happens because all application load configuration only once at starting time.

We will AQMP to get things works, we will install RabbitMQ you can learn more in details online.

We are now going to add/use few more dependencies

  • Actuator (add some features i.e., to check the status of the application)
  • Spring cloud Starter Bus AMQP

Add these dependencies to all of your project:

implementation ‘org.springframework.cloud:spring-cloud-starter-bus-amqp’

implementation ‘org.springframework.boot:spring-boot-starter-actuator’

Enable bus-refresh URL to refresh configuration using POST in Config Service

Install and run RabbitMQ Server

Please follow official documentation for the same.

Add RabbitMQ settings to all of the applications who want to connect with bus.

Just for testing purpose let add one more action/URL in User Service to read a property from Config Service and return it in response.

Start all the application and test this URL it should return like this

Now change the value in user-service.properties in Config Service then restart Config Service and use Spring Cloud Bus to broadcast the changes.

updated the value in config-service/user-service.properties

We have to send POST request to our bus-service.

Now no need to restart our User Service and let’s check we have updated value or not.

Now Spring Cloud Bus broadcast the new configuration to all services.

--

--

Code Dexterous

I am full stack developer. Works on different technology and lean to learn more.