说明

用于分布式上所有微服务都连接到消息总线上面。进行统一的通知

Config动态刷新

configClient

configClient通过/actuator/bus-refresh端点通知消息总线 消息总线通知线上的所有服务实例 调用/actuator/refresh端点进行配置更新

configClient改造

1.增加bus pom依赖

 <!--根据消息总线实现所有服务配置刷新-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

2.配置文件增加mq信息

spring:
rabbitmq: #更多mq配置看书331页
username: liqiang
password: liqiang
host: localhost
port: 5672

3.配置文件增加bus端点

management:
endpoints:
web:
exposure:
include: refresh,bus-refresh

4.完整配置文件

spring:
application:
name: config #对应{application}
cloud:
config:
profile: dev #映射{profile}
label: master #映射{label}
#uri: http://127.0.0.1:7001 #config server地址
username: liqiang #configserver身份认证用户名
password: liqiang #configserver身份认证密码
discovery:
service-id: CONFIG-SERVER #configserver的服务名
enabled: true #开启通过服务访问configserver的功能
fail-fast: true #快速响应spring.cloud.config.fail-fast=true
retry:
multiplier: 1.1 #默认间隔乘数 如果间隔是1000 下一次间隔是1100
max-interval: 2000 #默认最大间隔数(毫秒)
max-attempts: 6 #默认重试次数
initial-interval: 1000 #默认间隔数
rabbitmq: #更多mq配置看书331页
username: liqiang
password: liqiang
host: localhost
port: 5672
server:
port: 7002
eureka:
instance:
hostname: localhost #当前实例的主机名字
client:
serviceUrl:
defaultZone: http://peer1:1111/eureka/, http://peer2:1112/eureka/
#http://127.0.0.1:7002/actuator/refresh
management:
endpoints:
web:
exposure:
include: refresh,bus-refresh

5.复制2个配置文件 分别命名为peer1和peer2并且将端口改为不一致

6.将client instail打包

8.执行eurekaserver    config-server    通过命令启动2个client

java -jar /Users/liqiang/Desktop/java开发环境/mavenRegitstory/com/liqiang/spring-cloud-config-client/0.0.1-SNAPSHOT/spring-cloud-config-client-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1
java -jar /Users/liqiang/Desktop/java开发环境/mavenRegitstory/com/liqiang/spring-cloud-config-client/0.0.1-SNAPSHOT/spring-cloud-config-client-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2

9.测试

post请求http://127.0.0.1:7003/actuator/bus-refresh 测试没通过 只有7003实现了刷新

PS:最终测试时版本文本 不确定是版本差异还是bug 修改版本 重新测试

   <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>2.1.0.RELEASE</version>-->
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--<spring-cloud.version>Greenwich.M3</spring-cloud.version>-->
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>

10.修改git 77777为88888

posman访问http://localhost:7002/actuator/bus-refresh

可以看到总线上的7003服务 也刷新了

configServer

我们可以发现 通知总线上所有实例刷新配置由configServer来负责会更合理

1.configServer增加pom依赖

 <!--根据消息总线实现所有服务配置刷新-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

2.配置文件增加mq以及端点

spring:
rabbitmq: #更多mq配置看书331页
username: liqiang
password: liqiang
host: localhost
port: 5672
management:
endpoints:
web:
exposure:
include: health,info,bus-refresh

3.刷新配置改为访问server的/actuator/bus-refresh 就可以了

指定服务刷新

http://localhost:7001/actuator/bus-refresh?destination=CONFIG:7002  为服务名字为config同时端口为7002的刷新

ps:没测试通过应该改为

http://localhost:7001/actuator/bus-refresh/config:7002 刷新名为config 同时端口为7002的服务

http://localhost:7001/actuator/bus-refresh/config:** 为刷新名为config的所有服务

事件跟踪

1.设置spring.cloud.bus.trace.enabled=true

2开启端点httptrace

management:
endpoints:
web:
exposure:
include: health,info,bus-refresh,httptrace,trace

3.访问http://localhost:7001/actuator/bus-refresh

4.再访问http://127.0.0.1:7001/actuator/httptrace

5.跟老版本的/trace地址不一样输出内容也不一样感觉不利于分析

{
"traces": [{
"timestamp": "2019-01-23T00:51:47.346Z",
"principal": null,
"session": null,
"request": {
"method": "POST",
"uri": "http://localhost:7001/actuator/bus-refresh",
"headers": {
"content-type": ["application/json"],
"cache-control": ["no-cache"],
"postman-token": ["bfe920e9-66fb-42bf-b36f-13d577b9fab7"],
"user-agent": ["PostmanRuntime/7.4.0"],
"accept": ["*/*"],
"host": ["localhost:7001"],
"accept-encoding": ["gzip, deflate"],
"content-length": ["0"],
"connection": ["keep-alive"]
},
"remoteAddress": null
},
"response": {
"status": 204,
"headers": {}
},
"timeTaken": 3296
}, {
"timestamp": "2019-01-23T00:51:49.725Z",
"principal": null,
"session": null,
"request": {
"method": "GET",
"uri": "http://localhost:7001/config/dev/master",
"headers": {
"accept": ["application/xml, text/xml, application/json, application/*+xml, application/*+json"],
"user-agent": ["Java/1.8.0_181"],
"host": ["localhost:7001"],
"connection": ["keep-alive"]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Type": ["application/xml;charset=UTF-8"],
"Transfer-Encoding": ["chunked"],
"Date": ["Wed, 23 Jan 2019 00:51:49 GMT"]
}
},
"timeTaken": 58
}, {
"timestamp": "2019-01-23T00:51:49.621Z",
"principal": null,
"session": null,
"request": {
"method": "GET",
"uri": "http://localhost:7001/config/dev/master",
"headers": {
"accept": ["application/xml, text/xml, application/json, application/*+xml, application/*+json"],
"user-agent": ["Java/1.8.0_181"],
"host": ["localhost:7001"],
"connection": ["keep-alive"]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Type": ["application/xml;charset=UTF-8"],
"Transfer-Encoding": ["chunked"],
"Date": ["Wed, 23 Jan 2019 00:51:49 GMT"]
}
},
"timeTaken": 104
}, {
"timestamp": "2019-01-23T00:49:59.062Z",
"principal": null,
"session": null,
"request": {
"method": "POST",
"uri": "http://localhost:7001/actuator/bus-refresh",
"headers": {
"content-type": ["application/json"],
"cache-control": ["no-cache"],
"postman-token": ["470bc387-8f9b-4ddd-8655-66de72970a84"],
"user-agent": ["PostmanRuntime/7.4.0"],
"accept": ["*/*"],
"host": ["localhost:7001"],
"accept-encoding": ["gzip, deflate"],
"content-length": ["0"],
"connection": ["keep-alive"]
},
"remoteAddress": null
},
"response": {
"status": 204,
"headers": {}
},
"timeTaken": 3517
}, {
"timestamp": "2019-01-23T00:50:02.173Z",
"principal": null,
"session": null,
"request": {
"method": "GET",
"uri": "http://127.0.0.1:7001/actuator/httptrace",
"headers": {
"host": ["127.0.0.1:7001"],
"connection": ["keep-alive"],
"cache-control": ["max-age=0"],
"upgrade-insecure-requests": ["1"],
"user-agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.116"],
"accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],
"accept-encoding": ["gzip, deflate, br"],
"accept-language": ["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"],
"cookie": ["JSESSIONID=6369DFBED3CE1C799C4FC36E246CE502; CURRENT_COOKIE=84822DAAAAE4F96E04CBDE51132D0CCE"]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Type": ["application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"],
"Transfer-Encoding": ["chunked"],
"Date": ["Wed, 23 Jan 2019 00:50:01 GMT"]
}
},
"timeTaken": 4
}, {
"timestamp": "2019-01-23T00:50:01.319Z",
"principal": null,
"session": null,
"request": {
"method": "GET",
"uri": "http://localhost:7001/config/dev/master",
"headers": {
"accept": ["application/xml, text/xml, application/json, application/*+xml, application/*+json"],
"user-agent": ["Java/1.8.0_181"],
"host": ["localhost:7001"],
"connection": ["keep-alive"]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Type": ["application/xml;charset=UTF-8"],
"Transfer-Encoding": ["chunked"],
"Date": ["Wed, 23 Jan 2019 00:50:01 GMT"]
}
},
"timeTaken": 39
}, {
"timestamp": "2019-01-23T00:50:01.125Z",
"principal": null,
"session": null,
"request": {
"method": "GET",
"uri": "http://localhost:7001/config/dev/master",
"headers": {
"accept": ["application/xml, text/xml, application/json, application/*+xml, application/*+json"],
"user-agent": ["Java/1.8.0_181"],
"host": ["localhost:7001"],
"connection": ["keep-alive"]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Type": ["application/xml;charset=UTF-8"],
"Transfer-Encoding": ["chunked"],
"Date": ["Wed, 23 Jan 2019 00:50:01 GMT"]
}
},
"timeTaken": 86
}, {
"timestamp": "2019-01-23T00:49:53.411Z",
"principal": null,
"session": null,
"request": {
"method": "GET",
"uri": "http://127.0.0.1:7001/actuator/httptrace",
"headers": {
"host": ["127.0.0.1:7001"],
"connection": ["keep-alive"],
"cache-control": ["max-age=0"],
"upgrade-insecure-requests": ["1"],
"user-agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.116"],
"accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],
"accept-encoding": ["gzip, deflate, br"],
"accept-language": ["zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"],
"cookie": ["JSESSIONID=6369DFBED3CE1C799C4FC36E246CE502; CURRENT_COOKIE=84822DAAAAE4F96E04CBDE51132D0CCE"]
},
"remoteAddress": null
},
"response": {
"status": 200,
"headers": {
"Content-Type": ["application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"],
"Transfer-Encoding": ["chunked"],
"Date": ["Wed, 23 Jan 2019 00:49:53 GMT"]
}
},
"timeTaken": 52
}]
}

源码分析

事件跟踪跟书上不一样 所以暂时止步

Spring Cloud-Bus(十二)的更多相关文章

  1. Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin【Finchley 版】

    Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin[Finchley 版]  发表于 2018-04-24 |  随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请 ...

  2. Spring Cloud第十二篇 | 消息总线Bus

    ​ ​本文是Spring Cloud专栏的第十二篇文章,了解前十一篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring ...

  3. Spring Cloud(十二)声名式服务调用:Feign 的使用(下)

    前言 本文是对上一篇博文的扩充,很多平时用不到的特性就开始简略一写,Spring Cloud各版本之间的差距很大的,用不到的可能下一个版本就被kill掉了.由于笔者写本文开始的时候误解了Feign的继 ...

  4. Spring Cloud第十四篇 | Api网关Zuul

    ​ 本文是Spring Cloud专栏的第十四篇文章,了解前十三篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring C ...

  5. Spring Cloud(十):服务网关 Zuul(路由)【Finchley 版】

    Spring Cloud(十):服务网关 Zuul(路由)[Finchley 版]  发表于 2018-04-23 |  更新于 2018-05-09 |  通过之前几篇 Spring Cloud 中 ...

  6. Spring Boot + Spring Cloud 构建微服务系统(十):配置中心(Spring Cloud Bus)

    技术背景 我们在上一篇讲到,Spring Boot程序只在启动的时候加载配置文件信息,这样在GIT仓库配置修改之后,虽然配置中心服务器能够读取最新的提交信息,但是配置中心客户端却不会重新读取,以至于不 ...

  7. SpringCloud教程 | 第八篇: 消息总线(Spring Cloud Bus)

    一.安装rabbitmq 二.pom父文件 <?xml version="1.0" encoding="UTF-8"?> <project x ...

  8. 第七篇: 消息总线(Spring Cloud Bus)

    Spring Cloud Bus 将分布式的节点用轻量的消息代理连接起来.它可以用于广播配置文件的更改或者服务之间的通讯,也可以用于监控.本文要讲述的是用Spring Cloud Bus实现通知微服务 ...

  9. Spring Cloud (十五)Stream 入门、主要概念与自定义消息发送与接收

    前言 不写随笔的日子仿佛就是什么都没有产出一般--上节说到要学Spring Cloud Bus,这里发现按照官方文档的顺序反而会更好些,因为不必去后边的章节去为当前章节去打基础,所以我们先学习Spri ...

  10. 【SpringCloud 】第八篇: 消息总线(Spring Cloud Bus)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

随机推荐

  1. 【HDOJ 2255】奔小康赚大钱(KM算法)

    [HDOJ 2255]奔小康赚大钱(KM算法) 奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  2. 的Linq未提交之前插入/修改时重新查询不准确问题

    来园子已经两年了,每次都是看,这次咱也写一次. 说一下今天遇到的Linq问题: 每一次插入流水表时,都需要查找表中最大的流水号+1,并且将该流水号返回,但是在同一个SubmitChange之内插入多条 ...

  3. bzoj3555 [Ctsc2014]企鹅QQ——字符串哈希

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3555 很久以前就讲过哈希,但一直没写过题,所以这是哈希第一题! 哈希就是把一个字符串映射成一 ...

  4. vmware centos7 没有网络设备

    vmware centos7 没有网络设备 选择VMware 虚拟机模拟器为CentOS 64 即可;

  5. pair类型 这次遇到了,记录下来,方便彼此xue习

    首先,这个pair类型是在头文件utility.h中. 一个piar保存两个数据成员,是用来生成特定类型的模板,当创建一个pair时,我们必须提供两个类型名,pair的数据成员将具有对应的类型,两个类 ...

  6. EditPlus 1:更改默认编码方式

    打开软件点击上面的菜单栏Tools(工具),再找到Configure User Tools(用户配置工具)点击,再找到左边栏File点击,这个时候可以看到右边栏的Default encoding点击可 ...

  7. android 自定义view 前的基础知识

    本篇文章是自己自学自定义view前的准备,具体参考资料来自 Android LayoutInflater原理分析,带你一步步深入了解View(一) Android视图绘制流程完全解析,带你一步步深入了 ...

  8. 我和CSDN的那些事

    作者:朱金灿 来源:http://blog.csdn.net/clever101 前些日子收到这样一个邀请: CSDN的工作人员还来电给我确认是否能参加.开始我有点犹豫,毕竟是在工作日的晚上,毕竟离我 ...

  9. objectdatasouce的温故

    在做ecxel的时候,需要前台做一个联动的效果. 记录一下这个数据源的用法,大学时候用的,忘得差不多了 首先就是往页面拖拽一个objectdatasouce的控件 然后配置数据源: 选择业务对象(其实 ...

  10. 简繁体互换工具:opencc

    简繁体互换工具:opencc opencc是一个简体.繁体相互转换的命令行工具. 安装 下载软件包.在下载页面下载软件包(如1.0.4版本) 解压.通过命令解压:tar -xzvf opencc-1. ...