我们使用spring cloud分布式微服务云架构做了b2b2c的电子商务系统,除了架构本身自带的系统服务外,我们将b2b2c的业务服务进行了细粒度拆分,做成了不同的业务微服务。
当我们的业务系统越来越庞大复杂的时候,各种配置也会随之增多。配置文件只要一修改,会对commonservice-config配置中心先停止服务,然后再重新启动,最后使配置生效。
如果服务少,我们可以手动方式来启动,但是对业务和系统的稳定性肯定有一定的影响。
如果是成百上千的服务都靠手动操作,我估计运维人员或技术人员会疯掉的。
针对以上问题,commonservice-config服务端和业务微服务分别做了相关的配置,服务端负责将git(svn或本地文件系统)中存储的配置文件进行配置化(我们使用的是本地配置方案,方便直接将配置文件更新到linux上),
业务微服务通过配置从服务端配置中心获取相关配置,如果配置文件变动了,通过刷新业务微服务的方式,将最新的配置信息获取。
spring cloud Bus通过一个轻量级消息代理连接分布式系统的节点。这可以用于广播状态更改(如配置更改)或其他管理指令。
接下来,我们就来实施通过spring cloud Bus方案,动态刷新服务端配置,具体步骤如下:
1. commonservice-config服务配置可以参考之前的链接:
http://2147775633.iteye.com/admin/blogs/2396692
2. 业务微服务配置(以honghu-member-servcie会员服务为例):
pom文件配置:
<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>
yml文件配置:
server:
port: 5012
spring:
application:
name: honghu-member-client
profiles:
active: dev,discoveryClient
cloud:
config:
discovery:
enabled: true
service-id: commonservice-config-server
name: honghu-member
profile: dev
bus:
trace:
enabled: true #开启消息跟踪
rabbitmq:
host: 192.168.1.254
port: 5672
username: honghu
password: honghu
eureka:
client:
serviceUrl:
defaultZone: http://honghu:123456@localhost:8761/eureka/
instance:
prefer-ip-address: true
logging:
level:
root: INFO
org.springframework.security: INFO
management:
security:
enabled: false
security:
basic:
enabled: false
编写一个测试类(MemberController.java),用来获取配置项
package com.honghu.cloud.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RefreshScope
@RestController
public class MemberController {
@Value("${profile}")
private String profile;
@GetMapping("/profile")
public String getProfile() {
return this.profile;
}
}
3. 查看注册中心,commonservice-config、honghu-member-service服务是否已经注册成功
4. 访问一下profile,获取profile对应的配置信息(原配置):
访问http://localhost:7071/profile ==》 访问结果:123456
5. 修改config配置中心的配置文件,将profile=123456修改为honghu123456
再次访问http://localhost:7071/profile ==》 访问结果:123456
6. 使用spring cloud bus 刷新方案(使用post man测试工具进行测试)
http://localhost:7071/bus/refresh
再次访问http://localhost:7071/profile ==》 访问结果:honghu123456
到此,整个commonservice-config配置中心动态刷新方案整理完毕(需要源码可以加qq:2147775633)!!
欢迎大家和我一起学习spring cloud构建微服务云架构,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。
相关推荐
spring-cloud-config + spring-cloud-bus-amqp实现分布式集群配置动态更新,可更新实例对象,包含源码包+Rabbitmq安装包和安装说明
spring-cloud-config-eureka-bus:配置中心和消息总线示例(配置中心终结版) gateway-service-zuul:Spring Cloud Zuul使用初级篇 网关 均衡负载 spring-cloud-zuul:Spring Cloud Zuul使用高级篇 Filter 鉴权 熔断...
spring-cloud
spring-cloud-eureka Spring Cloud(一)服务的注册与发现(Eureka) ...spring-cloud-config-bus-rabbitMQ Spring Cloud(十一)高可用的分布式配置中心 Spring Cloud Bus 消息总线集成(RabbitMQ)
- [springcloud(九):配置中心和消息总线(配置中心终结版)](http://www.ityouknow.com/springcloud/2017/05/26/springcloud-config-eureka-bus.html) - [springcloud(十):服务网关zuul]...
spring-cloud-config-eureka-bus:配置中心和消息总线示例(配置中心终结版) gateway-service-zuul:Spring Cloud Zuul使用初级篇 网关 均衡负载 spring-cloud-zuul:Spring Cloud Zuul使用高级篇 Filter 鉴权 熔断...
包含内容: Spring Cloud系列教程 Spring Boot Spring Cloud Stream...springcloud-config-oracle-bus-kafka.zipspringcloud-feign.zip springcloud-producer.zip springcloud-producer-consumer.zip springcloudstudy.
Spring Cloud Bus配合Spring Cloud Config使用可以实现配置的动态刷新 spring cloud bus能管理和传播分布式系统间的消息,就像分布式执行器,可用于广播状态更改、时间推送等,也可以当做微服务间的通信通道 spring ...
微服务架构,是由一个个微小的服务集合而成的一个一套系统,服务多了,维护...再加上通过SpringCloud Bus,让配置文件能够自动刷新(这也应该是微服务应该必须有的一个效果),更加锦上添花了。 ---------------------
SpringCloud Bus 消息总线 SpringCloud Stream 消息驱动 SpringCloud Sleuth 分布式请求链路跟踪 SpringCloud Alibaba入门简介 SpringCloud Alibaba Nacos 服务注册和配置中心 SpringCloud Alibaba Sentinel ...
springcloud config bus 配套代码
.使用Spring Cloud搭建服务注册中心 ...27.Spring Cloud Bus整合RabbitMQ 28.Spring Cloud Bus整合Kafka 29.Spring Cloud Stream初窥 30.Spring Cloud Stream使用细节 31.Spring Cloud系列勘误
springcloud bus 总父pom 配置文件 springcloud bus 总父pom 配置文件 springcloud bus 总父pom 配置文件 springcloud bus 总父pom 配置文件
文档中详细介绍了spring cloud的相关组件,包含了服务发现与注册 Eureka,服务消费 Ribbon 和 Reign,链路监控 Sleuth,断路器(熔断器)Hystrix,分布式配置中心 Config,消息总线 Bus,服务网关 Zuul,Spring Boot...
spring cloud config/bus源码解读,,包含server端,client端,bus的运行原理
spring cloud demo,消费者,生产者,注册中心,可以借鉴一下
springcloud bus rabbitmq 分布式队列 http://knight-black-bob.iteye.com/blog/2356839
spring-cloud-microservices-development:Spring Cloud微服务开发。《 Spring Cloud微服务架构开发实战》
实践方志鹏博客搭建Springcloud+RabbitMQ+Config-client+config-server Eureka-server的微服务架构,通过/bus/refresh接口触发所有config-client自动从config-server重新读取配置文件。SpringCloud和SpringBoot版本...
SpringCloud之八 消息总线SpringCloudBus.pdf,微服务中消息总线的使用处理