Spring Cloud 2-Bus 消息总线(九)

在分布式配置中,客户端获取远程最新配置时(比如:Git),要手动发送POST请求客户端来刷新.在集群环境下,不是很方便.使用Spring Cloud Bus总线可以自动刷新客户端配置.
1.服务端配置
pom.xml
<!-- config-server 服务配置中心 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- bus 消息总线 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
application.yml
spring:
application:
name: config-bus-server
cloud:
config:
server:
git:
uri: https://github.com/xianghaizing/spring-cloud-learn
search-paths: config-repo
# 以下都是默认配置
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
server:
port: 8888
management:
endpoints:
web:
exposure:
include: bus-refresh # 暴露刷新节点 2.x版本需要手动开启
2.客户端配置
pom.xml
<!-- spring mvc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 配置中心client端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- bus 消息总线 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
application.yml
spring:
application:
name: config-bus-client
cloud:
config:
uri: http://localhost:8888
name: lyf # 远程文件的application名字
profile: dev
label: master
bus:
trace:
enabled: true
# 以下都是默认配置
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
server:
port: 8040
name
远程文件的application名字rabbitmq
RabbitMQ服务地址以及用户名和密码
Controller.java
@RefreshScope
@RestController
public class BusClientController {
@Value("${from}")
private String from;
@GetMapping("/from")
public String getFrom(){
return this.from;
}
}
@RefreshScope
必须添加才能自动刷新
3.自动刷新配置
依次启动:
- 启动RabbitMQ服务
- 启动服务端
- 启动多个客户端
验证顺序和方式跟之前一样.只是,现在要向服务端
发送请求,而不是客户端
!
POST: http://localhost:8888/actuator/bus-refresh
所有客户端的配置都已经更新.
Spring Cloud 2-Bus 消息总线(九)的更多相关文章
- 跟我学SpringCloud | 第八篇:Spring Cloud Bus 消息总线
SpringCloud系列教程 | 第八篇:Spring Cloud Bus 消息总线 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich.SR1 如无特 ...
- Spring Cloud(十一)高可用的分布式配置中心 Spring Cloud Bus 消息总线集成(RabbitMQ)
详见:https://www.w3cschool.cn/spring_cloud/spring_cloud-jl8a2ixp.html 上一篇文章,留了一个悬念,Config Client 实现配置的 ...
- Spring Cloud 系列之 Bus 消息总线
什么是消息总线 消息代理中间件构建一个共用的消息主题让所有微服务实例订阅,当该消息主题产生消息时会被所有微服务实例监听和消费. 消息代理又是什么?消息代理是一个消息验证.传输.路由的架构模式,主要用来 ...
- spring cloud bus 消息总线 动态刷新配置文件 【actuator 与 RabbitMQ配合完成】
1.前言 单机刷新配置文件,使用actuator就足够了 ,但是 分布式微服务 不可能是单机 ,将会有很多很多的工程 ,无法手动一个一个的发送刷新请求, 因此引入了消息中间件 ,常用的 消息中间件 是 ...
- Spring Cloud 入门教程(十):和RabbitMQ的整合 -- 消息总线Spring Cloud Netflix Bus
在本教程第三讲Spring Cloud 入门教程(三): 配置自动刷新中,通过POST方式向客户端发送/refresh请求, 可以让客户端获取到配置的最新变化.但试想一下, 在分布式系统中,如果存在很 ...
- SpringCloud之Config配置中心+BUS消息总线原理及其配置
一.配置中心作用 在常规的开发中,每个微服务都包含代码和配置.其配置包含服务配置.各类开关和业务配置.如果系统结构中的微服务节点较少,那么常规的代码+配置的开发方式足以解决问题.当系统逐步迭代,其微服 ...
- SpringCloud(六)Bus消息总线
Bus 消息总线 概述 分布式自动刷新配置功能 Spring Cloud Bus 配合 Spring Cloud Config使用可以实现配置的动态刷新 Bus支持两种消息代理:RabbitMQ和Ka ...
- 使用 Spring Cloud Stream 构建消息驱动微服务
相关源码: spring cloud demo 微服务的目的: 松耦合 事件驱动的优势:高度解耦 Spring Cloud Stream 的几个概念 Spring Cloud Stream is a ...
- 几种常见的微服务架构方案简述——ZeroC IceGrid、Spring Cloud、基于消息队列
微服务架构是当前很热门的一个概念,它不是凭空产生的,是技术发展的必然结果.虽然微服务架构没有公认的技术标准和规范草案,但业界已经有一些很有影响力的开源微服务架构平台,架构师可以根据公司的技术实力并结合 ...
随机推荐
- day12(表达式,推导式,名称空间与作用域,函数的嵌套定义)
一,复习 # 字符串的比较 # -- 按照从左往右比较每一个字符,通过字符对应的ascll进行比较 # print('a' > 'A') #True # print('ac' > 'ab' ...
- keras04 - 阿狗阿猫识别 面向对象编程
参考:https://www.bilibili.com/video/av32756783
- Django(七)缓存、信号、Form
大纲 一.缓存 1.1.五种缓存配置 1.2配置 2.1.三种应用(全局.视图函数.模板) 2.2 应用多个缓存时生效的优先级 二.信号 1.Django内置信号 2.自定义信号 三.Form 1.初 ...
- Nginx访问配置
配置HTTP协议(使用80默认端口,非HTTPS配置SSL)访问网站 包括RestAPI的配置和RestAPI文档的配置 例如: server { # 配置为HTTP协议 listen ; serve ...
- 一、操作m'y's'ql
一.创建framework框架的控制台默认不支持mysql
- 调用webservice帮助类
using System;using System.CodeDom;using System.CodeDom.Compiler;using System.Collections.Generic;usi ...
- Allow Only Ajax Requests For An Action In ASP.NET Core
ASP.NET Core offers attributes such as [HttpGet] and [HttpPost] that allow you to restrict the HTTP ...
- Linux C Socket简单实例与详细注释
最近做的东西与socket十分紧密,所以很好奇它具体是如何实现的,以前也有了解过,但是又忘记了,于是把它记录下来,以便日后查看. 服务器端:server.c #include <sys/type ...
- [搬运] 将 Visual Studio 的代码片段导出到 VS Code
原文 : A Visual Studio to Visual Studio Code Snippet Converter 作者 : Rick Strahl 译者 : 张蘅水 导语 和原文作者一样,水弟 ...
- docker添加阿里云专属镜像
阿里云镜像地址:https://link.zhihu.com/?target=https%3A//cr.console.aliyun.com/%23/accelerator 根据提示开启容器镜像服务, ...