legend
legend

Reputation: 273

Refreshing the config changes with Spring Cloud Bus

I am building an application using Spring Cloud config server as a centralized location for keeping properties file. And I have multiple client applications getting configuration data from config server.

But instead of manually refreshing each client applications to pull latest changes in properties file after commit I'm using Spring cloud bus and Kafka as a message broker so that all changes broadcast to client application. Below are the pom file and properties file.

ConfigServer : pom

       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

application.properties :

  server.port = 8980

bootstrap.properties :

   spring.cloud.bus.enabled=true
   spring.cloud.config.server.git.uri= "some path"

Config Client : pom

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

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

application.properties :

server.port=8982

spring.cloud.bus.refresh.enabled: true
spring.cloud.bus.env.enabled: true
endpoints.spring.cloud.bus.refresh.enabled: true
endpoints.spring.cloud.bus.env.enabled: true

spring.cloud.stream.kafka.binder.autoAddPartitions=true
spring.cloud.stream.kafka.binder.zkNodes=localhost:2181
spring.cloud.stream.kafka.binder.brokers=localhost:9892

bootstrap.properties :

    spring.application.name=department-service
    spring.cloud.config.uri=http://localhost:8980
    management.security.enabled=false

But after making changes to local git repository file and after commiting when I am trying to pull latest changes using "http://localhost:8982/actuator/bus-refresh" endpoint, it is giving error as below :

{
"timestamp": "2019-01-29T08:49:21.569+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/actuator/bus-refresh"

}

Upvotes: 3

Views: 3291

Answers (2)

Tadese
Tadese

Reputation: 21

You need to include "management.endpoints.web.exposure.include=bus-refresh" in your config server application.properties. Afterward, send a GET request to this URL localhost:8012/actuator to see the available LINKS for refreshing the config changes. You will see the JSON below

{
"_links": {
    "self": {
        "href": "http://localhost:8012/actuator",
        "templated": false
    },
    "busrefresh-destinations": {
        "href": "http://localhost:8012/actuator/busrefresh/{*destinations}",
        "templated": true
    },
    "busrefresh": {
        "href": "http://localhost:8012/actuator/busrefresh",
        "templated": false
    }
}

Then you can send a POST to this URL localhost:8012/actuator/busrefresh

Upvotes: 2

Dhruv Dhar
Dhruv Dhar

Reputation: 14

you need to include "management.endpoints.web.exposure.include=bus-refresh" in your config server application.properties and hit this url

http://localhost:8980/actuator/bus-refresh

Upvotes: -1

Related Questions