继续前面搭建的spring cloud。

这里是基于rabbitMQ搭建的,首先需要在电脑上安装rabbitMQ。

在client端和server端分别加上如下依赖

  compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-bus-amqp', version: '1.0.1.RELEASE'

AMQP (Advanced Message Queuing Protocol)是一种通讯协议,而rabbitMQ就是使用的这种通讯协议。

client端的application.properties加上如下

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=root
spring.rabbitmq.password=root

client端的configuration包下的配置类文件上应该有@ConfigurationProperties()注解

@Data
@Component
@ConfigurationProperties(prefix = "fzk")
public class BaseConfiguration {
private String nick;
}

在每个注入了这个configuration的类加上@FreshScope注解

@RestController
@RefreshScopepublic class ClientApplication {
@Autowired
Base base; @RequestMapping(value = "/foo", method = RequestMethod.GET)
public String foo() { return base.getNick();
}
}

完成之后执行下面命令下载jar包。

gradle build
gradle eclipse

server端同样编译后,先启动server端,在启动client端。

浏览器上输入localhost:8889/foo会看到获取到的数据。去gitlab修改下fzk-beta.properties,重新在浏览器上输入,发现现在获取的还是原来的数据,并没有修改。从服务端(http://localhost:8888/fzk/beta)可以获取到最新的数据。这里想让client端不重启服务就能获取到更新后的数据需要手动发送一个post请求到client端(http://localhost:8889/fresh)

$ curl -X POST http://localhost:8889/refresh
["config.client.version","fzk.nick"]

所以想数的时,这里并不是完全的自动。还需要调用一个接口,这个接口一般是通过存放config的push事件来触发的,如果一个服务可以直接写在webhook中。但是如果需要触发多个服务自动更新,可以在jenkins配置一个job,webhook出去这个job,这个job来触发多个服务的post请求操作。

最新文章

  1. nodejs处理url工具
  2. css3 总结02
  3. ACM: 强化训练-海贼王之伟大航路-dfs-枝减
  4. 纸上谈兵:伸展树(splay tree)
  5. invoke和beginInvoke
  6. 用include来处理模板的问题
  7. 安装VMware-tools的问题
  8. 搭建Ubuntu12.04交叉编译服务器
  9. spring-线程池(3)
  10. 201521145048《java程序与设计》第9周学习总结
  11. Kinect外包团队— 2016中国VR开发者论坛第一期
  12. MT4下载历史数据
  13. Ajax增删改查-----------查
  14. Java log4j
  15. webpack4对第三方库css,项目全局css和vue内联css文件提取到单独的文件(二十二)
  16. Distinct Subsequences leetcode java
  17. 以sb7code为基础创建一个基本的OpenGL项目
  18. [转]Eclipse 项目转移到Android Studio遇到的问题
  19. 用select (多路复用)模拟一个 socket server
  20. HDU 2993 MAX Average Problem(斜率DP经典+输入输出外挂)

热门文章

  1. Iterative (non-recursive) Merge Sort
  2. ASP.NET综合管理ERP系统100%源代码+所有开发文档
  3. 解决eclipse中overlaps the location of another project: 'xxxx'
  4. 正则表达式 判断IP 数字
  5. SQLServer 2017安装时的错误:Polybase要求安装Oracle JRE 7更新51或更高版本
  6. Android适配方案小结(二)
  7. ssh隧道远程连接mysql
  8. 关于浮点数的json解析
  9. freemarker在xml文件中遍历list数据
  10. oracle如何进行索引监控分析和优化