What is Spring Cloud Bus and why is it required in Microservices
In this tutorial we will learn to use Spring Cloud Bus to apply dynamic configuration updates and in the previous tutorials we have learnt about Spring Cloud Config Server configuration.
When our microservices start up they fetch configuration properties form the Spring Cloud Config Server automatically and our problem statement lies here i.e., our micro services fetch the configuration properties only once at the start up time.
If we make a change to one of the values in our configuration properties which are currently stored in the GIT repository. Our micro services will not receive those newly updated changes unless we restart them so that they can load the new changes.
Restarting all the microservices due to the configuration changes every time is not an easy task and to overcome this problem, we use Spring Cloud Bus.
Spring Cloud Bus will help us to push configuration changes to all our microservices while they are running and without a restart.
To configure a Spring Cloud Bus, there is no need for a new Standalone micro service application and instead we can add Spring Cloud bus and other dependencies to the Spring Cloud Config server and also to the other micro services which has a requirement to receive the dynamic application configuration updates.
This will make our micro services work as a listeners or subscribers to receive updates from the Spring Cloud Config server. Once any modifications are done in the configurations, they will be broadcasted to all the subscribed microservices with the help of messaging technology.
The protocol used by the messaging technology is AMQP i.e., Advanced Message Queuing Protocol and it enables the applications that is used to connect and scale.
This messaging is asynchronous and it decouples application by separating the sending and receiving data. We will use a message broker RabbitMQ which acts as an intermediary for messaging and gives applications a common platform to send and receive messages and for messages a safe place to live until they are received.