【问题标题】:Refreshing the config changes with Spring Cloud Bus使用 Spring Cloud Bus 刷新配置更改
【发布时间】:2019-01-29 09:06:48
【问题描述】:

我正在构建一个应用程序,使用 Spring Cloud 配置服务器作为保存属性文件的集中位置。而且我有多个客户端应用程序从配置服务器获取配置数据。

但是,我没有手动刷新每个客户端应用程序以在提交后提取属性文件中的最新更改,而是使用 Spring 云总线和 Kafka 作为消息代理,以便所有更改都广播到客户端应用程序。下面是 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"

配置客户端: 嘭

        <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

但是在对本地 git 存储库文件进行更改并提交之后 当我尝试使用“http://localhost:8982/actuator/bus-refresh”端点提取最新更改时,出现如下错误:

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

}

【问题讨论】:

    标签: java spring-boot apache-kafka spring-boot-actuator


    【解决方案1】:

    您需要在配置服务器 application.properties 中包含“management.endpoints.web.exposure.include=bus-refresh”。之后,向该 URL localhost:8012/actuator 发送 GET 请求,以查看可用的 LINKS 以刷新配置更改。您将在下面看到 JSON

    {
    "_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
        }
    }
    

    然后你可以发送 POST 到这个 URL localhost:8012/actuator/busrefresh

    【讨论】:

      【解决方案2】:

      您需要在配置服务器 application.properties 中包含“management.endpoints.web.exposure.include=bus-refresh”并点击此网址

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

      【讨论】:

        猜你喜欢
        • 2020-07-11
        • 2019-03-20
        • 2020-09-10
        • 2021-03-15
        • 1970-01-01
        • 2016-09-09
        • 2019-09-16
        • 2019-07-01
        • 2016-09-29
        相关资源
        最近更新 更多