Spring Cloud Bus集成,不再/bus/refresh得到404了

Spring Cloud Bus集成

目前工程的架子已经搭建完成,RabbitMQ也开始使用,因此考虑集成Spring Cloud Bus,这样修改变量时就不用考虑再要重启工程了。

目前最新版本的SpringCloudBus,不再是/bus/refresh,而是/actuator/bus-refresh

SpringBoot与SpringCloud版本

版本如下

  • Spring Boot 2.1.9.RELEASE
  • Spring Cloud Greenwich.RELEASE
1. 配置中心Spring Cloud Server

修改如下

  • 1.1 增加pom配置
        <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>
  • 1.2 增加properties配置(替换相应配置)
# spring cloud bus config
spring.rabbitmq.host=Your Host
spring.rabbitmq.port=Your Ip
spring.rabbitmq.username=Your Username
spring.rabbitmq.password=Your Password
spring.rabbitmq.virtual-host=Your Virutal Host

# spring cloud bus 关键, 开启对应的端点
management.endpoints.web.exposure.include=bus-refresh,bus-env
  • 1.3 刷新配置的URL
    POST请求接口即可刷新,ContentType要用application/json,以前的/bus/refresh已经不再被使用了,现在的和actuator集成再一起了
http://localhost:8888/actuator/bus-refresh

上面的URL是刷新所有的注册到一起的微服务应用,至于单个刷新暂时没有考虑,其他教程有提到直接在后面加参数指定即可。

2. 某个微服务应用

修改如下

  • 2.1 增加pom配置
        <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.2 增加properties配置(替换相应配置,同Config配置中心配置)
# spring cloud bus config
spring.rabbitmq.host=Your Host
spring.rabbitmq.port=Your Ip
spring.rabbitmq.username=Your Username
spring.rabbitmq.password=Your Password
spring.rabbitmq.virtual-host=Your Virutal Host

# spring cloud bus 关键, 开启对应的端点
management.endpoints.web.exposure.include=bus-refresh,bus-env
  • 2.3 增加@RefreshScope
    对于启动类以及使用@Value的类,都要加上@RefreshScope,否则即使修改了配置,进行了配置刷新,也不会刷新已存储的旧值。
3. 具体实际使用

具体微服务应用工程和Congif配置中心工程配置好之后,请求Config配置中心的/actuator/refresh接口,然后就会发现具体微服务应用工程打印刷新配置的日志,甚至会直接说明哪些配置刷新了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值