当前位置: 首页 > 知识库问答 >
问题:

使用Spring Cloud Bus刷新配置更改

弓嘉纳
2023-03-14

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

但我使用Spring cloud bus和Kafka作为消息代理,以将所有更改广播到客户端应用程序,而不是手动刷新每个客户端应用程序,以便在提交后获取属性文件中的最新更改。下面是pom文件和属性文件。

配置服务器:pom

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

application.properties:

  server.port = 8980

独自创立属性:

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

配置客户端: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

独自创立属性:

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

但在对本地git存储库文件进行更改后,以及在我尝试使用http://localhost:8982/actuator/bus-“刷新”endpoint,给出如下错误:

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

}

共有2个答案

夏侯昊明
2023-03-14

您需要在配置服务器应用程序中包含“management.endpoints.web.exposure.include=bus refresh”。属性并点击此url

http://localhost:8980/actuator/bus-刷新

东方夕
2023-03-14

您需要在配置服务器应用程序中包含“management.endpoints.web.exposure.include=bus refresh”。财产。之后,向这个URL localhost:8012/exactor发送GET请求,以查看刷新配置更改的可用链接。您将看到下面的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
    }
}

然后,您可以向这个URL localhost:8012/exactor/busrefresh发送帖子

 类似资料:
  • 我最近将Firebase remote config添加到我的项目中,以便远程管理一些应用程序设置。 由于Firebase的性质,配置只能在客户端每12小时更新一次。当我慢慢地将变量添加到远程配置中时,我意外地创建了以下场景: 用户的应用程序版本A在远程配置上的变量很少。 应用程序从Firebase更新变量 用户将应用程序版本更新为A+1,该版本在远程配置中具有新变量 应用程序尝试从firebas

  • 我在pom中添加了以下依赖项,以便使用Spring云 spring-cloud.version芬奇利 这是我打算刷新的bean: 访问控制器中的bean: 在应用程序配置中设置的属性: 无法刷新模式的值。有人能指出这段代码中的错误吗?我的属性文件位于未在git中提交的文件夹中,因此我没有使用spring-cloud d-config。

  • 我需要从文件中删除封面 调试时,元素已正确删除,但输出封面上的元素仍在此处。 有没有更新/刷新文档xml的方法,即使更改是从低级别发生的,我们如何刷新文档以保持更新

  • 我有一个具有2个视图\控制器的应用程序: 谢谢你。

  • 本文向大家介绍SpringCloud配置刷新原理解析,包括了SpringCloud配置刷新原理解析的使用技巧和注意事项,需要的朋友参考一下 我们知道在SpringCloud中,当配置变更时,我们通过访问http://xxxx/refresh,可以在不启动服务的情况下获取最新的配置,那么它是如何做到的呢,当我们更改数据库配置并刷新后,如何能获取最新的数据源对象呢?下面我们看SpringCloud如何

  • 考虑以下服务,如何使用/actuator/refreshendpoint动态修改缓存配置 使用以下默认配置 假设设置为maximumsize=50,expireafteraccess=300s 在GreetingService中添加@refreshScope不起作用。不知何故,我需要指示Spring Boot重新创建CacheManager? null