Centralized Configuration and Message Bus in Spring Cloud Microservices

Challenges with Manual Configuration Refresh

In a micorservice architecture using Spring Cloud Config, refreshing configuration changes on each client typically requires sending a POST request to the /actuator/refresh endpoint. While this works for a small number of clients, it becomes inefficient and cumbersome as the number of microservices grows. To address this, Spring Cloud Bus offers a centralized and automated solution.

Introduction to Spring Cloud Bus

Spring Cloud Bus connects distributed nodes using a lightweight message broker. It enables broadcasting state changes, such as configuration updates, across all connected services. Internally, it uses Spring Boot’s auto-configuration to extend applications and establish inter-service communication channels. Currently, it is most commonly implemented using AMQP brokers like RabbitMQ or Kafka.

Conceptually, Spring Cloud Bus acts as a communication backbone for distributed systems, leveraging the broadcast capabilities of messsage queues to propagate events. This is especially useful in scenarios like configuration management, where all instances need to be notified of a change simultaneously.

Setting Up RabbitMQ

Ensure RabbitMQ is running and accessible. This article assumes RabbitMQ is already installed and configured with default settings on localhost:5672 using the default credentials.

Configuring Spring Cloud Config Server

1. Add Required Dependenceis

Update your pom.xml to include the Spring Cloud Bus AMQP starter:

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

2. Configure RabbitMQ in application.yml

spring:
  cloud:
    bus:
      trace:
        enabled: true
management:
  endpoints:
    web:
      exposure:
        include: "*"
spring:
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest

Updating the Spring Cloud Config Client

1. Add Bus and Actuator Dependencies

Include the same bus and actuator dependencies in the client application:

<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>

2. Configure RabbitMQ in Client

Use the same RabbitMQ configuration as in the server:

spring:
  cloud:
    bus:
      trace:
        enabled: true
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest
management:
  endpoints:
    web:
      exposure:
        include: "*"

Testing the Setup

  1. Start the Eureka discovery server.
  2. Launch the Spring Cloud Config Server and Client applications.
  3. Access the configuration endpoints to verify initial values, e.g., http://localhost:8001/neo-config/dev and http://localhost:8003/hello.
  4. Update the configuration file in the remote Git repository.
  5. Send a POST request to the /actuator/bus-refresh endpoint on the Config Server to trigger a global refresh.
  6. Verify that the updated configuration is reflected across all clients without manually refreshing each one.

Tags: Spring Cloud Spring Cloud Config Spring Cloud Bus RabbitMQ Configuration Management

Posted on Sat, 19 Sep 2026 16:47:04 +0000 by kingpin393