-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.txt
149 lines (87 loc) · 3.82 KB
/
README.txt
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
Spring cloud config 搭建 及 老版Spring 集成 spring cloud config 项目
项目说明:
github:https://github.com/Eric-ly/hconfig
github的配置文件地址:https://github.com/Eric-ly/hconfig-properties
cloudeureka: spring boot的应用注册中心
ConfligClientNoSpringBoot: 非spring boot 应用 使用 应用配置中心
hconfigclient:spring boot的 应用配置中心的 客户端
hconfigserver:spring boot的 应用配置中心的服务端
使用说明:
1.启动 应用注册中心
(1)入口类:EurekaServerApplication IDE debug 或者用命令
(2)配置:
server.port=8761
eureka.instance.hostname=localhost
2.启动 配置中心的服务端
(1)入口类:ConfigServerApplication
(2)配置:
端口:
spring.application.name=config-server
server.port=9001
gitlab :来源
spring.cloud.config.server.git.uri=https://github.com/Eric-ly/hconfig-properties.git
spring.cloud.config.server.git.searchPaths=configRepo
spring.cloud.config.server.git.username=
spring.cloud.config.server.git.password=
spring.cloud.config.server.git.basedir=src/main/resource/config
# //加载到ConfigServer项目所在的本地目录的位置, 可以不用配置
消息总线,用来自动热更新,配置的是mq的地址,需要自己启
# 添加cloud bus 消息总线,配合webhook 实现 所有client的消息热更新
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
## 刷新时,关闭安全验证
management.security.enabled=false
## 开启消息跟踪
spring.cloud.bus.trace.enabled=true
注册中心:
#注册中心地址
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
3.启动 非spring boot的 ConfligClientNoSpringBoot
(1)配置 应用名
cloud-config-context.properties
spring.application.name=config-client
(2)IDE添加tomcat,然后启动
(3)测试
http://localhost:8888/hello
结果: 配置文件都读取到了
search-pproperties : collection :{{engine}} demo: {{solr}} ||| wosb-properties: demo : {{ a}} name: {{ wosb }} path: {{ /}} single value : test?{{ abcdegggg }}
4.spring boot的 配置中新 客户端( 自动热更新)hconfigclient
(1)入口类 entryApplication
(2)配置:
(1) 应用名+ 配置中心的 服务端
spring.application.name=config-client
spring.cloud.config.label=master
spring.cloud.config.profile=dev
spring.cloud.config.uri= http://localhost:9001/
server.port=8888
(2)
#注册中心地址
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
(3)
## 刷新时,关闭安全验证
management.security.enabled=false
## 开启消息跟踪
spring.cloud.bus.trace.enabled=true
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
(4) 测试
(提交代码触发post请求给bus/refresh ----server端接收到请求并发送给Spring Cloud Bus
----Spring Cloud bus接到消息并通知给其它客户端 ----其它客户端接收到通知,请求Server端获取最新配置
----全部客户端均获取到最新的配置)
-------
congfig server
先启动server
http://localhost:9001/config-server-dev.properties
后启动client
http://localhost:8888/hi
client :curl -X POST http://localhost:8888/refresh 更新
cloud bus 消息总线
(1) client 发送,curl -X POST http://localhost:8888/bus/refresh
(2)改进
(提交代码触发post请求给bus/refresh ----server端接收到请求并发送给Spring Cloud Bus
----Spring Cloud bus接到消息并通知给其它客户端 ----其它客户端接收到通知,请求Server端获取最新配置
----全部客户端均获取到最新的配置)