内容简介:每个项目都需要引入hystrix包,或者在框架里引入,并且官方仅支持java编写可熔断调用无应用内代码,不需要了解特定语言相关知识,比如hystrix内部的线程池,信号量等。
每个项目都需要引入hystrix包,或者在框架里引入,并且官方仅支持java
<!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core --> <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>hystrix-core</artifactId> <version>1.5.18</version> </dependency> 复制代码
编写可熔断调用
public class CommandHelloWorld extends HystrixCommand<String> { private final String name; public CommandHelloWorld(String name) { super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")); this.name = name; } @Override protected String run() { return "Hello " + name + "!"; } @Override protected String getFallback() { return "Hello World"; } } 复制代码
destinationrule
apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: httpbin spec: host: httpbin trafficPolicy: connectionPool: tcp: maxConnections: 1 http: http1MaxPendingRequests: 1 maxRequestsPerConnection: 1 outlierDetection: consecutiveErrors: 1 interval: 1s baseEjectionTime: 3m maxEjectionPercent: 100 复制代码
无应用内代码,不需要了解特定语言相关知识,比如hystrix内部的线程池,信号量等。
配置能力
hystrix
hystrix官方提供大量配置项可供使用 Hystrix
istio
istio同样提供大量的指标可供配置通信路由
hystrix和istio都提供大量的配置项进行自定义使用
业务侵入性
hystrix硬编码在业务代码里
destinationrule不在业务代码里
灵活性
destinationrule 随时可以添加和删除,无需改动代码,并且支持所有语言的应用
hystrix 硬编码,必须改动应用代码或者配置,仅限 java 使用,并且python, php等语言无官方支持
运维难度
hystrix需要改代码或者配置,虽然有apollo等统一的配置中心,但是还是需要了解hystrix的相关知识,并且可能需要重启应用等额外操作
destionationrule 运维只需了解istio相关知识即可 通过命令: kubectl apply -f 可以直接应用 通过命令: kubectl delete destinationrules.networking.istio.io 服务名 一键删除
维护
hystrix需要开发人员和运维人员同时参与维护
destinationrule只需要运维人员维护
熔断监控
hystrix
hystrix可以在java应用内硬编码报警脚本,比如: RegisterCommandExcutionHook.java
关键代码如下:
HystrixPlugins.getInstance().registerCommandExecutionHook(new HystrixCommandExecutionHook() { @Override public <T> void onFallbackStart(HystrixInvokable<T> commandInstance) { HystrixCommand hystrixCommand = (HystrixCommand) commandInstance; String commandKey = hystrixCommand.getCommandKey().toString(); log.error("Hystrix: {} 接口开始降级", commandKey); super.onFallbackStart(commandInstance); } }); 复制代码
虽然在应用内可以使用代码采集足够的监控指标,但是硬编码,并且需要开发成本
istio
istio可以借助谷歌开源的prometheus进行监控,不需要应用内的开发,并且默认就支持钉钉等丰富的报警推送
不过hystrix和istio这两套环境可以同时存在
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Kubernetes 服务网格工具对比
- [Grid 网格布局教程]显式网格和隐式网格之间的区别
- 精彩的无服务器时代:不仅有服务网格,还有事件网格
- 服务网格重蹈ESB的覆辙?为什么需要SMI服务网格接口? - samnewman
- 什么是服务网格?
- [译] 初识 NGINX 服务网格
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Hacking Growth
Sean Ellis、Morgan Brown / Crown Business / 2017-4-25 / USD 29.00
The definitive playbook by the pioneers of Growth Hacking, one of the hottest business methodologies in Silicon Valley and beyond. It seems hard to believe today, but there was a time when Airbnb w......一起来看看 《Hacking Growth》 这本书的介绍吧!