当前位置:网站首页>Bus message bus
Bus message bus
2022-07-07 06:57:00 【RB_ VER】
summary
Spring Cloud Bus coordination spring cloud config Use dynamic refresh that enables configuration .
spring cloud bus It's a framework for linking nodes of a distributed system to a lightweight messaging system .
It integrated. Java Event handling mechanism and message middleware function .
Bus Two kinds of message agents are supported :RabbitMQ and Kafka.
spring cloud bus It can manage and disseminate messages between distributed systems , It's like a distributed actuator , Can be used for broadcast state change , Event push, etc , It can also be used as a communication channel between microservices .
Bus : In the system of microservice Architecture , A lightweight message broker is usually used to build a common message topic , And connect all micro service instances in the system . Because messages generated in this topic will be listened and consumed by all instances , So it is called message bus . Each instance on the bus , Can easily broadcast some messages that need to be known to other instances connected to the subject .
The basic principle :config client Instances are listening to MQ The same one topic( The default is SpringCloudBus). When a service refreshes data , It will put this information into topic in , In this way, the other monitors the same topic The service will be informed , Then update your configuration .
spring cloud bus Dynamic refresh global broadcast
design idea :
Use the message bus to trigger a client /bus/refresh, And refresh the location of all clients
Use message bus to trigger a server ConfigServer Of /bus/refresh Endpoint , And refresh the configuration of all clients .
The second architecture is more reasonable , The first unreasonable reason :
- Breaking the single responsibility of microservices , Because microservices themselves are business modules , It should not be responsible for configuration refresh .
- Destroy the peer-to-peer of each microservice node .
- There are certain limitations .
establish cloud-config-center-3344 The module serves as the server of the configuration center .
Please refer to 【 Microservices 】 Integrate spring cloud config.
pom.xml
<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>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
...
application.yml
server:
port: 3344
spring:
application:
name: cloud-config-center
cloud:
config:
server:
git:
uri: [email protected]:zzyybs/springcloud-config.git
search-paths:
- springcloud-config
label: master
rabbit:
host: localhost
port: 5672
username: guest
password: guest
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
management:
endpoints:
web:
exposure:
include: 'bus-refresh'
Configuration required rabbitmq.
newly build cloud-config-client-3366 modular .
pom.xml rely on
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</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-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
bootstrap.yml
server:
port: 3366
spring:
application:
name: config-client
cloud:
config:
label: master # Branch name
name: config # Profile name
profile: dev # Read suffix name The above three comprehensive :master On the branch config-dev.yml Configuration file for
uri: http://localhost:3344 # Configure center address
rabbit:
host: localhost
port: 5672
username: guest
password: guest
eureka:
client:
service-url:
defautZone: http://localhost:7001/eureka
management: # Monitor exposure endpoints
endpoints:
web:
exposure:
include: "*"
ConfigClientMain3366
@EnableEurekaClient
@SpringBootApplication
public class ConfigClientMain3366{
public static void main(String[] args) {
SpringApplication.run(ConfigClientMain3366.class,args);
}
}
@RestController
@RefreshScope
public class ConfigClientController{
@Value("${server.port}")
private String serverPort;
@Value("${config.info}")
private String configInfo;![ Insert picture description here ](https://img-blog.csdnimg.cn/1bd0130034f44a7ca19f9923e72157e6.png#pic_center)
@GetMapping("/configinfo")
public String configInfo() {
return "serverPort: "+serverPort+" configInfo: "+configInfo;
}
}
In the same way cloud-config-client-3355 modular .
test :
modify GitHub Add version number to the configuration file :
config:
info: "master branch,springcloud-config/config-dev.yml version=2"
send out post request :
curl -X POST "http://localhost:3344/actuator/bus-refresh"
visit http://localhost:3366/configinfo, Get configuration information , The discovery has been refreshed .
spring cloud bus Dynamic refresh fixed-point notification
It means that a specific instance takes effect instead of all .
http://localhost: Port number of the configuration center /actuator/bus-refresh/{destination}
destination= Microservice name : Port number
边栏推荐
- 企业如何进行数据治理?分享数据治理4个方面的经验总结
- 请教一下,监听pgsql ,怎样可以监听多个schema和table
- Take you to brush (niuke.com) C language hundred questions (the first day)
- 多个kubernetes集群如何实现共享同一个存储
- JDBC database connection pool usage problem
- This article introduces you to the characteristics, purposes and basic function examples of static routing
- Can't you really do it when you are 35 years old?
- Kotlin之 Databinding 异常
- [noi simulation] regional division (conclusion, structure)
- Get the city according to IP
猜你喜欢
RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)`问题解决
Prime partner of Huawei machine test questions
ESXI挂载移动(机械)硬盘详细教程
MOS管参数μCox得到的一种方法
【从零开始】win10系统部署Yolov5详细过程(CPU,无GPU)
大促过后,销量与流量兼具,是否真的高枕无忧?
Maze games based on JS
当前发布的SKU(销售规格)信息中包含疑似与宝贝无关的字
Jetpack Compose 远不止是一个UI框架这么简单~
How can gyms improve their competitiveness?
随机推荐
2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书
服装门店如何盈利?
mysql查看bin log 并恢复数据
libcurl返回curlcode说明
带你刷(牛客网)C语言百题(第一天)
RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)`问题解决
Google Chrome browser released patch 103.0.5060.114 to fix the 0-day vulnerability
途家、木鸟、美团……民宿暑期战事将起
[noi simulation] regional division (conclusion, structure)
学术报告系列(六) - Autonomous Driving on the journey to full autonomy
Etcd database source code analysis -- starting from the start function of raftnode
Matlab tips (29) polynomial fitting plotfit
工具类:对象转map 驼峰转下划线 下划线转驼峰
MySQL view bin log and recover data
Abnova 免疫组化服务解决方案
Mysql---- import and export & View & Index & execution plan
Stack and queue-p79-10 [2014 unified examination real question]
DB2获取表信息异常:Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][t4][1065][12306][4.25.13]
from .onnxruntime_pybind11_state import * # noqa ddddocr运行报错
Answer to the first stage of the assignment of "information security management and evaluation" of the higher vocational group of the 2018 Jiangsu Vocational College skills competition