配置中心的服务端跟客户端我们已经搭建好了,但有个问题:如果git中的内容修改了,客户端能及时获取数据吗?
测试一下会发现不能,必须重启客户端才能刷新数据,这明显不是我们想要的。spring cloud的配置中心对这部分的实现是使用amqp协议,需要安装rabbitmq。具体操作如下:
--------------------------------------------------------------------------------------------------------------------------------
1、服务端跟客户端均添加依赖:
<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>
2、服务端去掉安全校验或者开启http basic 认证,前者简单,我们采用前者。client端添加rabbitmq相关配置:
management: security: enabled: false
client端mq相关配置
rabbitmq: host: localhost port: 5672 username: guest password: guest
3、分别启动服务端跟客户端,测试。
启动服务端跟客户端后,修改码云的代码,将demo1/client-a-master.yml中的msg改为:client1 配置文件测试用例----修改过啦,访问http://localhost:9999/testConfig,


发现内容并没有及时更新,,,,这是因为服务端没有刷新的缘故。
用post方式访问一下:http://localhost:8080/refresh或者http://localhost:8080/bus/refresh,两者区别是集群环境下刷新单机跟刷新全局,会看到服务端跟客户端均打印了日志,
再次访问,可以看到内容已经刷新了

虽然现在我们已经能拿到修改过的数据了,但每次都要手动刷新一下也还是有些麻烦的,万一忘了呢?这个就要用webhooks来解决了。
打开码云的webhooks页面,添加刚才config-server的post刷新地址即可:
打开码云的webhooks页面,添加刚才config-server的post刷新地址即可:

--------------------------------------------------------------------------------------------------------------------------------
待解决疑问:
1、config-server怎么从git获取数据,怎么管理数据,客户端怎么获取怎么保存?
2、自动刷新部分,rabbitmq为什么只有client端配置了,server端是怎么发给client端的?