博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring cloud微服务分布式云架构-config配置自动刷新
阅读量:7211 次
发布时间:2019-06-29

本文共 6314 字,大约阅读时间需要 21 分钟。

本项目采用版本选择:

springboot的版本是2.1.2.RELEASE

springcloud的版本是Greenwich.SR1

springcloud仓库使用的是Gitee

1、下载并安装RabbitMq

下载地址:http:/ /www.rabbitmq.com/download.html

Spring Cloud大型企业分布式微服务云架构源码请加一七九一七四三三八零

2、SpringCloud Config Server端配置

config-server pom.xml的配置如下

4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.2.RELEASE
com.lee.self
config
0.0.1-SNAPSHOT
config
Demo project for Spring Boot
1.8
Greenwich.SR1
org.springframework.cloud
spring-cloud-config-server
org.springframework.cloud
spring-cloud-starter-bus-amqp
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-snapshots
Spring Snapshots
https://repo.spring.io/snapshot
true
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
spring-snapshots
Spring Snapshots
https://repo.spring.io/snapshot
true
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
复制代码

config-server的bootstrap.yml的配置如下:

server:  port: 9010spring:  application:    name: config  cloud:    config:      server:        git:		  #码云的用户名和密码及地址          username: ****           password: ****          uri: https://gitee.com/lijiaxi118/blog-repoeureka:  client:    service-url:      defaultZone: http://localhost:9001/eureka/management:  endpoints:    web:      exposure:        include: "bus-refresh"复制代码

3、SpringCloud Config Client端配置

config-client pom.xml配置如下:

4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.2.RELEASE
com.lee.self
user
0.0.1-SNAPSHOT
user
Demo project for Spring Boot
1.8
Greenwich.SR1
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.cloud
spring-cloud-starter-bus-amqp
org.springframework.boot
spring-boot-starter-test
test
io.springfox
springfox-swagger-ui
2.4.0
io.springfox
springfox-swagger2
2.4.0
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
复制代码

config-client的bootstrap.yml配置:

spring:  application:    name: user  cloud:    config:      discovery:        service-id: config        enabled: true      profile: proeureka:  client:    service-url:      defaultZone: http://localhost:9001/eureka/server:  port: 9005ribbon:  eureka:    enabled: true复制代码

4、测试

启动注册中心eureka

启动config server 访问localhost:9010/user-dev.yml监测是否启动成功

启动config client

在client项目中写一个测试类如下

测试类如下

@Component@RefreshScope@Data@ConfigurationProperties(prefix = "spring.redis")public class RedisConfig {    private String host;    private String port;}@RestController@RequestMapping("/test")public class ConfigController {    @Autowired    private RedisConfig redisConfig;    @RequestMapping("/print")    public String print() {        return "host:" +"\t" + redisConfig.getHost()+"====Port:"+redisConfig.getPort();    }}复制代码

页面访问http://localhost:9005/test/print,查看结果

修改gitee中的user-dev.yml文件

使用postman的post请求访问http://localhost:9010/actuator/bus-refresh

继续浏览器访问http://localhost:9005/test/print查看结果是否更新

自此config的刷新基本完成,最后一步在gitee中配置webhooks,每一次push修改之后都会自动的通知到各个客户端

4、配置仓库中的webhooks

点击gitee中的管理——》webhooks,填入外网访问的路径即可。

转载于:https://juejin.im/post/5c91a515e51d4504455d52ff

你可能感兴趣的文章
svn 的使用
查看>>
react-router-dom
查看>>
nohup后台执行
查看>>
转贴:Cache 总结
查看>>
自学或者复习的话,runnoob这个网站不错~~
查看>>
快速用梯度下降法实现一个Logistic Regression 分类器
查看>>
python基础学习2
查看>>
[Tyvj 1728]普通平衡树
查看>>
css3
查看>>
table 中,如何使得单元格的内容不换行,单元格不被撑开
查看>>
Hibernate中session.get()和session.load()的区别
查看>>
泊松分布(Poisson distribution)的简单认识
查看>>
Android之使用传感器获取相应数据
查看>>
Jquery中html()方法 and "click"绑定后代元素
查看>>
HashMap和Hashtable的详细区别
查看>>
virutalbox虚拟机硬盘扩容
查看>>
自学计划
查看>>
dp-01背包问题 (升级)
查看>>
MySQL数据库唯一性设置(unique index)
查看>>
Windows性能计数器(命令行方式)
查看>>