Spring Cloud Hystrix理解与实践(一):搭建简单监控集群
前言
在分布式架构中,所谓的断路器模式是指当某个服务发生故障之后,通过断路器的故障监控,向调用方返回一个错误响应,这样就不会使得线程因调用故障服务被长时间占用不释放,避免故障的继续蔓延。Spring Cloud Hystrix实现了断路器,线程隔离等一系列服务保护功能,它是基于Netflix的开源框架Hystrix实现的。
目的不是介绍Hystrix的与原理、及其使用等(有时间也要记录啊),而是通过实战搭建一个简单的监控集群,使用Hystrix Dashboard仪表盘动态监控展示以此来加深对Hystrix的认识与理解,为什么要记录呢?这是因为网上资料甚少(或版本过低,不适用),同时加之书中的Spring Cloud版本与现在Spring Boot 2.x差距明显。
本文主要参考《Spring Cloud 微服务实战》(PDF电子版,需要的朋友可以私聊或评论)
一、Hystrix 仪表盘
1、认识Hystrix仪表盘
HystrixCommand与HystrixObserableCommand实例执行过程中记录的重要信息称之为Hystrix仪表盘,以供内部或者外部进行查询使用。Spring Cloud整合仪表盘组件Hystrix Dashboard,主要用来实时监控Hystrix的各项指标信息,可以帮我们快速发现系统中存在的问题,从而及时地采取应对措施。
1)加入依赖
特别注意Spring Boot 2.x版本引入的hystrix-dashboard依赖,不然可能访问不了http://localhost:port/hystrix仪表盘页面,注解@EnableHsytrixDashboard也可能找不到
<!-- hystrix 容错机制 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId><version>${spring-cloud-eureka.version}</version></dependency><!-- actuator监控 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Spring Boot 2.x以上版本 spring-cloud-starter-netflix-hystrix-dashboard 仪表盘,以下版本则需要spring-cloud-starter-hystrix-dashboard--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId><version>${spring-cloud-eureka.version}</version></dependency>
2)添加配置
# 应用实例 spring:application:name: hystrix-dashboardserver:port: 8000# actuator开放所有端点,Spring Boot 2.x与1.x不同,具体请查询 management:endpoints:web:exposure:include: "*"
3)增加注解:应用主类加上@EnableHsytrixDashboard,启用Hystrix Dashboard功能。
@EnableHystrixDashboard // 开启Hystrix仪表盘 @SpringBootApplication public class HystrixMonitorApplication {public static void main(String[] args) {SpringApplication.run(HystrixMonitorApplication.class, args);}}
4)访问http://localhost:8000/hystrix界面如下:
2、监控页面介绍
从界面中我们就可以看到Hystrix Dashboard支持不同的三种监控方式:
1) 默认的集群监控:通过URL http://turbine-hostname:port/turbine.stream
2) 指定的集群监控:通过URL http://turbine-hostname:port/turbine.stream?cluster=[clusterName]开启
3) 单体应用的监控:URL http://hystrix-app:port/hystrix.stream开启,实现对具体某个服务实例的监控
前两者关于集群的监控需要整合turbine才能实现,而对于单体实例节点需要访问实例的/hystrix.stream接口实现,我们自然需要为服务实例添加端点。只需要添加acutator与hystrix依赖,应用主程序类开启断路器@EnableCircuitBreaker注解与@EnableHystrixDashboard注解即可。
其中的参数:
1)Delay:用来控制服务器上轮询监控信息的延迟时间,默认为2000ms。可以通过该配置该属性降低客户端的网络和CPU消耗。
2)Ttile:对应进入监控后的的标题,如Hystrix,则进入监控页面后如下图红框标题
此外,我们在URL框输入我们需要监听的某个服务实例/hystrix.stream接口,如http://localhost:8081/hystrix.stream,就可以进入监控页面
监控页面参数介绍:
1) 实心圆与曲线的含义
实心圆颜色:健康度从绿色、黄色、橙色、红色递减
实心圆大小:会根绝实例的请求流量发生变化,流量越大实心圆就越大。
曲线:用来记录2分钟内流量的相对变化,可以通过它来观察流量的上升与下降。
2) 其它的指标参数:鼠标停留会显示相应的说明
二、简单监控架构
1、监控单实例的架构
(1)架构图
(2)过程说明
- 服务提供者:HELLO-SERVICE,提供一个接口如:http:/HELLO-SERVER/hello,让消费者通过restTemplate(封装好的HTTP)调用消费
- 服务消费者:RIBBON-CONSUMER,会有ribbon承担负载均衡的作用,分别轮询访问HELLO-SERVER-1与HELLO-SERVICE-2
- 注册中心:Spring Cloud Eureka,主要负责服务治理:服务的注册、续约、剔除(更新)等
- Hystrix仪盘表:通过/hystrix.stream接口监控某个服务实例,动态展示仪表盘数据。
然而现在只针对一个实例来监控,而分布式系统中往往有很多实例,我们就需要利用Turbine和Hystrix Dashboard配置实现对集群的监控
2、监控聚合服务
需要通过Turbine来聚合RIBBON-CONSUMER-1与服务RIBBON-CONSUMER-2成一个服务展示监控信息,并输出到Hystrix Dashboard中,只显示一张监控图,但是注意Hosts的数量为2
(1)架构图
(2)过程说明
同上述“单实例监控”,不同的是这次服务消费者有RIBBON-CONSUMER-1与RIBBON-CONSUMER-2两个,通过/turbine.stream接口聚合两个服务实例(实则就是同一个服务不同实例)成一个服务,共同动态展示整个集群的动态数据。对于集群来说关注的是服务集群的高可用性,所以Turbine会将相同服务作为整体看待。
三、代码实践
1、实践前的准备
首先本示例使用的是Idea+Maven构造的项目工程的,所以先熟悉下idea如何构建一个简单的Spring Boot项目
1)新建项目:File->New->Project
2)选择Spring Initializr,选择默认的https://start.spring.io(需要联网),点击Next
3)填写项目信息
4)选择依赖,这里我们只需要选择web依赖即可,之后再加入相关Spring Cloud Hystrix的依赖,这是因为Spring Boot版本与Spring Cloud版本有相对应的关系,不然会冲突项目到处都是坑
5)查看Spring Boot与Spring Cloud的版本对应关系从官网(https://spring.io/projects/spring-cloud)中查看,这里使用的是Spring Boot 2.0.6.RELEASE与Spring Cloud Fincley.SR1
6)我们需要搭建以下的架构
从图中我们知道我们需要:
1)两个Eureaka Server提供高可用的注册中心:
分别对应工程eureka-server与eureke-slave-server,配置文件中register-with-eureka与fetch-registry保持默认true,相互注册进行同步维护服务实例列表。
2)两个服务提供者实例提供HELLO-SERVICE/hello服务:
对应工程hello-service,打包成jar包。
通过命令 java -jar hello-service-0.0.1-SNAPSHOT.jar --server.port=8081 开启实例HELLO-SERVICE-1
通过命令 java -jar hello-service-0.0.1-SNAPSHOT.jar --server.port=8082 开启实例HELLO-SERVICE-2
3)两个服务消费者实例消费HELLO-SERVICE/hello服务
对应工程ribbon-consumer,使用ribbon开启负载均衡,使用hystrix开启断路器功能,之后打包jar包。
通过命令 java -jar ribbon-consumer-0.0.1-SNAPSHOT.jar --server.port=8083 开启实例RIBBON-CONSUMER-1
通过命令 java -jar ribbon-consumer-0.0.1-SNAPSHOT.jar --server.port=8084 开启实例RIBBON-CONSUMER-2
4)开启Spring Cloud Circuit Breaker 断路器
引入相关依赖,应用程序中开启注解即可,具体请看下面示例。
5)消费者开启负载均衡器
服务消费者直接通过调用被@LoadBalanced注解修饰过的RestTemplate来实现面向服务的接口调用
6)开启Hystrix Dashboard仪表盘
引入hystrix dashboard、turbine等相关依赖,应用程序中开启注解即可,具体请看下面示例。
2、代码示例
1)服务治理工程:eureka-service与eureka-slave-service
pom.xml文件内容:eureka-service与eureka-slave-service都相同
<properties><java.version>1.8</java.version><spring-cloud.version>Finchley.SR1</spring-cloud.version><spring-cloud-eureka.version>1.4.6.RELEASE</spring-cloud-eureka.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Spring Cloud Eureka--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId><version>${spring-cloud-eureka.version}</version></dependency><!-- 可以删除(需要同时删除Test类),但是为了不麻烦就保留了 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
eureka-service的application.yml文件:
server:port: 5678 eureka:instance:hostname: master# slave注册中心urlclient:service-url:defaultZone: http://slave:5679/eureka/# 关闭保护模式server:enable-self-preservation: false
eureka-slave-service的application.yml文件:
server:port: 5679 eureka:instance:hostname: slaveclient:service-url:defaultZone: http://master:5678/eureka/server:enable-self-preservation: false
注:需要在hosts文件中添加slave/master域名解析。
应用程序类开启@EnableEurekaServer注解,表明是注册中心服务器
@EnableEurekaServer @SpringBootApplication public class EurekaSlaveServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaSlaveServerApplication.class, args);}}
2)服务提供者工程:hello-service
pom.xml文件内容:
注:这里加入的依赖是spring-cloud-starter-eureka,不是spring-cloud-starter-eureka-server
<properties><java.version>1.8</java.version><spring-cloud.version>Finchley.SR1</spring-cloud.version><spring-cloud-eureka.version>1.4.6.RELEASE</spring-cloud-eureka.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId><version>${spring-cloud-eureka.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
application.yml配置文件:
spring:application:name: hello-service # 注册中心url eureka:client:service-url:defaultZone: http://master:5678/eureka/,http://slave:5679/eureka/instance:# 定义服务失效的时间,默认为90s。lease-expiration-duration-in-seconds: 60# 续约任务的调用时间间隔,默认为30slease-renewal-interval-in-seconds: 10
应用程序增加注解@EnableEurekaClient
@EnableEurekaClient @SpringBootApplication public class EurekaClientApplication {public static void main(String[] args) {SpringApplication.run(EurekaClientApplication.class, args);}}
编写/hello接口,提供消费者调用
@RestController public class HelloController {@RequestMapping(value = "/index", method = RequestMethod.GET)public String index(){return "Hello World";} }
3)服务消费者工程:ribbon-consumer
消费者服务工程是相对比较复杂的,需要几个步骤:
- 实现ribbon负载均衡功能:增加@LoadBalanced
- 实现hystrix断路器容错功能:增加@EnableCircuitBreaker
- 增加actuator监控:增加actuator/hystrix.stream端点,提供hystrix仪表盘monitor使用
- 编写容错降级服务:发生异常超时等情况之后,做相应容错处理
- 重新注册restTemplate:增加@LoadBalanced实现负载均衡
- 开启请求缓存:对请求数据做缓存,减少压力
- 指定groupName与commandName
pom文件:既然要监控服务实例,自然要在该服务中添加Hystrix与actuator依赖。
<properties><java.version>1.8</java.version><spring-cloud.version>Finchley.SR1</spring-cloud.version><spring-cloud-eureka.version>1.4.6.RELEASE</spring-cloud-eureka.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId><version>${spring-cloud-eureka.version}</version></dependency><!-- ribbon 负载均衡 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-ribbon</artifactId><version>${spring-cloud-eureka.version}</version></dependency><!-- hystrix 容错机制 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId><version>${spring-cloud-eureka.version}</version></dependency><!-- actuator监控 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
HelloService: 实现请求处理+降级服务+命令名指定+请求缓存(http://HELLO-SERVER/hello接口并没有涉及数据交互,这里只做展示)
@Service public class HelloService {private final Logger logger = LoggerFactory.getLogger(HelloService.class);@Autowiredprivate RestTemplate restTemplate;/*** 消费者调用服务,并且开启断路器指定回调函数* 同步执行实现* @return*/@CacheResult // 请求命令开启缓存(可以指定缓存key)@HystrixCommand(fallbackMethod = "helloFallback", groupKey = "HelloGroup", commandKey = "HelloKey") // 指定熔断回调函数public String helloService(){long start = System.currentTimeMillis();// 模拟消息服务时间, getForEntity调用HELLO-SERVER服务的hello接口String result = restTemplate.getForEntity("http://HELLO-SERVICE/hello", String.class).getBody();long end = System.currentTimeMillis();logger.info("Spend time: "+(end - start));return result;}/*** 通过@CacheKey指定缓存key* @param id* @return*/@CacheResult@HystrixCommandpublic User getUserById(@CacheKey String id){User user = restTemplate.getForObject("http://HELLO-SERVICE/hello", User.class);return user;}/*** 更新数据:更新缓存(删除失效缓存)* @param user*/@CacheRemove(commandKey = "getUserById")@HystrixCommandpublic void update(@CacheKey("id") User user){restTemplate.postForObject("http://HELLO-SERVICE/hello", user, User.class);}/*** 获取cache key* @param id* @return*/public String getUserByCacheKey(String id){logger.info("获取缓存key....");return id;}/*** 消费者调用服务,并且开启断路器指定回调函数* 异步执行实现* @return*/@HystrixCommand(fallbackMethod = "helloFallback") // 指定熔断回调函数public Future<String> helloAsyncService(){return new AsyncResult<String>(){@Overridepublic String invoke(){return restTemplate.getForEntity("http://HELLO-SERVICE/hello", String.class).getBody();}};}/*** 降级服务* @return*/public String helloFallback(){return "error";} }
View Code
ConsumerController:对外调用接口/ribbon-consumer。
@RestController public class ConsumerController {@AutowiredHelloService helloService;@RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET)public String helloConsumer(){return helloService.helloService();} }
应用程序类RibbonConsumerApplication:开启断路器,开启服务发现,注册restTemplate,开启负载均衡
注:可以用@SpringCloudApplication代替,因为@SpringCloudApplication=@EnableCircuitBreaker+@EnableDiscoveryClient+@SpringBootApplication
@EnableCircuitBreaker // 开启断路器,也可以使用@SpringCloudApplication @EnableDiscoveryClient // 开启服务发现,也可以使用@SpringCloudApplication @SpringBootApplication public class RibbonConsumerApplication {/*** 注册RestTemplate bean* 并开启负载均衡* @return*/@Bean@LoadBalancedRestTemplate restTemplate(){return new RestTemplate();}public static void main(String[] args) {SpringApplication.run(RibbonConsumerApplication.class, args);}}
application.yml文件:
# 服务消费者 spring:application:name: ribbon-consumer# 注册中心地址 eureka:client:service-url:defaultZone: http://master:5678/eureka/,http://slave:5679/eureka/ server:port: 9000 # 开放所有端点,与Spring boot 1.x版本有差异 management:endpoints:web:exposure:include: "*"
4)仪盘表Hystrix Dashboard工程:hystrix-dashboard
pom文件:注意这里的hystrix-dashboard依赖于Spring boot 1.x引入的版本是不同的,具体看注释
<properties><java.version>1.8</java.version><spring-cloud.version>Finchley.SR1</spring-cloud.version><spring-cloud-eureka.version>1.4.6.RELEASE</spring-cloud-eureka.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- hystrix 容错机制 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId><version>${spring-cloud-eureka.version}</version></dependency><!-- actuator监控 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Spring Boot 2.x以上版本 spring-cloud-starter-netflix-hystrix-dashboard 仪表盘,以下版本则需要spring-cloud-starter-hystrix-dashboard--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId><version>${spring-cloud-eureka.version}</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
应用程序类:开启仪表盘注解@EnableHystrixDashboard
@EnableHystrixDashboard // 开启Hystrix仪表盘 @SpringBootApplication public class HystrixMonitorMonitorApplication {public static void main(String[] args) {SpringApplication.run(HystrixMonitorMonitorApplication.class, args);}}
application.yml:
spring:application:name: hystrix-dashboardserver:port: 8000# 开放所有端点 management:endpoints:web:exposure:include: "*"
5)turbine集群监控工程:turbine-monitor
通过turbine来聚合RIBBON-CONSUMER服务的监控信息,并提供/turbine.stream接口输出给Hystrix Dashboard进行展示
pom.xml文件:增加turbine依赖+actuator依赖
<properties><java.turbineversion>1.8</java.turbineversion><spring-cloud.version>Finchley.SR1</spring-cloud.version><spring-cloud-eureka.version>1.4.6.RELEASE</spring-cloud-eureka.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><!-- actuator监控 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-turbine</artifactId><version>${spring-cloud-eureka.version}</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
application.yml文件:
spring:application:name: turbine-monitor server:port: 8001# 注册中心地址 eureka:client:service-url:defaultZone: http://master:5678/eureka/,http://slave:5679/eureka/ turbine:# 指定需要收集监控信息的服务名(一定是大写,服务注册后都是大写)app-config: RIBBON-CONSUMER# 同一主机上的服务通过主机+端口区分(默认同一个主机上聚合成一个服务)combine-host-port: true# 当启动多个turbine服务构建不同的聚合集群,该参数可以区分不同的聚合集群# 同时可以在Hystrix Stream的URL中指定Cluster参数指定cluster-name-expression: new String("default")# 指定聚合哪些集群,多个使用","分割,默认为default。aggregator:cluster-config: default
应用程序类TurbineMonitorApplication :开启turbine监控
@SpringBootApplication @EnableTurbine // 开启turbine集群监控 @EnableDiscoveryClient public class TurbineMonitorApplication {public static void main(String[] args) {SpringApplication.run(TurbineMonitorApplication.class, args);}}
至此,所有的项目已经构建完毕,我们现在可以理清整个架构图,使架构图更加具体易懂。通过端口+IP的指定,我们可以清楚集群中每个角色的信息:
启动项目:
第一步:启动高可用的注册中心,访问注册中心http://slave:5679或者http://master:5678
实例列表中两个eureka服务实例已经相互注册
并且已经相互注册为同步备份服务器,在http://slave:5679中(http://master:5678同理)
第二步:启动服务提供者实例,开启HELLO-SERVICE-1与HELLO-SERVICE-2服务
执行命令:
java -jar hello-service-0.0.1-SNAPSHOT.jar --server.port=8081 开启HELLO-SERVICE-1,保留CMD窗口
java -jar hello-service-0.0.1-SNAPSHOT.jar --server.port=8082 开启HELLO-SERVICE-2,保留CMD窗口
查看注册中心是否已经注册:
第三步:启动服务消费者实例,开启RIBBON-CONSUMER-1与RIBBON-CONSUMER-2服务
执行命令:
java -jar ribbon-consumer-0.0.1-SNAPSHOT.jar --server.port=8083 开启RIBBON-CONSUMER-1,保留CMD窗口
java -jar ribbon-consumer-0.0.1-SNAPSHOT.jar --server.port=8084 开启RIBBON-CONSUMER-2,保留CMD窗口
查看注册中心是否已经注册:
第四步:启动turbine-monitor项目,访问http://localhost:8001/turbine.stream
可能一开始的时候一直ping或者返回的data甚少,如下图:
这是因为我们还没有访问http://localhost:8083/ribbon-consumer或者http://localhost:8084/ribbon-consumer接口,访问后会有很多监控数据返回,如下图:
第五步:启动hystrix-dashboard项目,开启hystrix仪表盘监控,输入URL:http://localhost:8001/turbine.stream,点击Monitor Stream,进入监控页面
注:
若一开始一直显示Loading,原因同上,都是因为我们还没有访问http://localhost:8083/ribbon-consumer或者http://localhost:8084/ribbon-consumer接口
若一开始Hosts的数目只有1的话,说明我们只访问了http://localhost:8083/ribbon-consumer或者http://localhost:8084/ribbon-consumer接口其中一个,或者其中一个还没启用。同时启动并访问后就会显示Hosts数目为2
正常是这样的:
第六步:观察监控图、负载均衡。
1)观察负载均衡:
不断访问http://localhost:8083/ribbon-consumer或者http://localhost:8084/ribbon-consumer,可以看到服务提供实例不断交替打印日志,实际上就是轮询负载均衡
2)观察监控图:
代码中已经有模拟超时,如果超时(默认为2000ms)则会显示error字样,监控图中的超时数量会增加1
增加访问http://localhost:8083/ribbon-consumer或者http://localhost:8084/ribbon-consumer速度(不断刷新),可以看到监控图中的流量图呈上升趋势
总结
Spring Cloud的两个重要角色Spring Cloud ribbon与Spring Cloud Hystrix可以整合为Feign,Feign除了提供这两个强大的功能外,还提供了一种声明式的Web服务端定义方式。在Spring Cloud Feign的实现下,我们只需要创建一个接口并用注解的方式陪着它,即可完成对服务提供方的接口绑定,简化了在使用Spring Cloud Ribbon时自行封装服务调用客户端的开发量。同时Spring Cloud Feign扩展了Spring MVC的注解支持。
本文可能篇幅过长,但是每一步都很仔细,包括架构图都是自己理解之后所画。经过这段时间的学习,抽出差不多8小时的编写(中间浏览器崩溃几次,从头来过三次),终于写完了本篇博文,但是仍然有不足之处,敬请见谅,之后再慢慢摸索学习,希望自己能有所收获!
转载于:https://www.cnblogs.com/jian0110/p/10912893.html
Spring Cloud Hystrix理解与实践(一):搭建简单监控集群相关推荐
- Spring Cloud Hoxton 版本微服务项目搭建 admin 监控客户端
Spring Cloud Hoxton 版本微服务项目搭建 admin 监控客户端 前言 在上一篇文章博主已经讲解了admin 管理中心服务项目如何创建,不会的话可以前往学习,传送门:Spring C ...
- Spring Cloud 学习笔记(四)-Spring Cloud Hystrix
Spring Cloud 学习笔记(四)-Spring Cloud Hystrix 由于前一阵子项目的原因,今天才继续弄上,今天想学习一下Hystrix组件 这个组件还挺抽象的,最开始我一直没太明白, ...
- 基于 Spring Cloud 的服务治理实践
http://www.infoq.com/cn/articles/spring-cloud-based-service-governance 大家好,我是来自贝壳金控的赵文乐,目前主要从事架构方面的工 ...
- Spring Cloud Config 配置中心实践过程中,你需要了解这些细节!
本文导读: Spring Cloud Config 基本概念 Spring Cloud Config 客户端加载流程 Spring Cloud Config 基于消息总线配置 Spring Cloud ...
- 贝壳金控赵文乐:基于 Spring Cloud 的服务治理实践
大家好,我是来自贝壳金控的赵文乐,目前主要从事架构方面的工作.今天我想跟大家分享<基于 Spring Cloud 的服务治理实践>.我先简单向大家介绍一下服务治理的概念,然后介绍实际案例中 ...
- Spring Cloud 2.x系列之Feign整合断路器监控Hystrix Dashboard
SVN多版本库环境的搭建 OAuth 2.0是什么?看这篇文章就够了. 前端 Java Python等资源合集大放送 Ribbon可以整合整合断路器监控Hystrix Dashboard,Feign也 ...
- 基于 Kubernetes 和 Spring Cloud 的微服务化实践
写在前面 网易云容器平台期望能给实施了微服务架构的团队提供完整的解决方案和闭环的用户体验,为此从 2016 年开始,我们容器服务团队内部率先开始进行 dogfooding 实践,看看容器云平台能不能支 ...
- Spring Cloud的全局封装实践
前言 跨应用的全局封装通过模仿java的异常抛出实现,通过各个服务使用相同的接口返回格式实现服务消息的传递,在规范化的同时快速定位真正出现问题的服务. 全局接口返回格式分为外部接口格式和内部接口格式, ...
- spring cloud Hystrix
spring cloud Hystrix 文章目录 spring cloud Hystrix pom.xml依赖 开启短路器功能 服务降级 @HystrixCommand的fallbackMethod ...
最新文章
- Linux系统版 lscpu
- python的快速入门-Python如何快速入门的基础知识
- 业内首创普惠保险,看国泰产险如何借助数据进行智能化的升级和战略转型
- mysql数据库主从同步配置教程--数据库同步
- Bat_To_Exe_Converter 乱码 中文
- Disassembly3:variable
- DP--POJ 2241
- 将一个类改成线程_看了这个有趣的例子,相信你就秒懂多线程同步了
- 验证Java编程环境是否成功时出现“'javac'不是内部或外部命令,也不是可运行的程序或批处理文件”
- centos安装守护进程工具supervisor
- linux centos7 iso镜像下载,CentOS 7镜像文件下载
- 交换机的接口类型和Ensp中线缆类型
- scrapy重试机制_Scrapy项目之User timeout caused connection failure(异常记录)
- Python3自然语言(NLTK)——语言大数据
- 小码哥教育笔记之VueDay01课程回顾
- excel 第一讲:认识excel
- 小刘的BUG (MySQL错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using passw)
- java application_运行java application时,总是报错
- R语言使用quantmod包的getSymbols函数从指定金融数据源获取指定时间段的股票数据、从雅虎金融读取著名的苹果公司的全部股票数据
- 头歌Educoder实验:C++ 面向对象 - 类的继承与派生