SpringCloud之八SpringCloudBus(消息总线)

使用spring cloud bus实现集群的配置全自动更新
继续使用上一篇文章的两个工程进行改造

首先

电脑上安装RabbitMQ
安装方式 参考

服务端

添加

1
2
3
4
5
<!-- 消息总线-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

application.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
server:
port: 8899

spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/felixjee/SpringCloudConfig.git
password:
username:
default-label: master
search-paths:
#配置rabbitmq
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${server.port}
client:
service-url:
defaultZone: http://localhost:8761/eureka/

management:
#refresh接入点显式暴露出来
endpoints:
web:
exposure:
include: refresh,health,info,bus-refresh #指定监控项。默认开启了health、info。我们这里加入了refresh
base-path: /actuator # 用于指定actuator的URL路径。1.X默认是/,2.X默认是/actuator
endpoint:
health:
show-details: always # 用于展示监控项详细信息,默认不展示
server:
port: 8988 #用于指定actuator端口。如果不指定则与系统服务端口一致,建议修改

客户端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

<dependencies>
<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.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>

application.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
spring:
cloud:
config:
label: master #对应git的分支。如果配置中心使用的是本地存储,则该参数无用
profile: dev #对应{profile}部分
name: userservice #对应{application}部分
#单个配置
uri: http://localhost:8888/
#配置重试机制
retry:
initial-interval: 2000
max-attempts: 2000
max-interval: 2000
multiplier: 1.2
fail-fast: true
bus:
#动态刷新配置
refresh:
enabled: true
#跟踪总线事件
trace:
enabled: true
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /

eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
instance-id: ${spring.application.name}:${server.port}
prefer-ip-address: true


management:
#refresh接入点显式暴露出来
endpoints:
web:
exposure:
include: refresh,health,info,bus-refresh #指定监控项。默认开启了health、info。我们这里加入了refresh
base-path: /actuator # 用于指定actuator的URL路径。1.X默认是/,2.X默认是/actuator
endpoint:
health:
show-details: always # 用于展示监控项详细信息,默认不展示
server:
port: 8983 #用于指定actuator端口。如果不指定则与系统服务端口一致,建议修改
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值