1.ribbonè´è½½å衡详解
2.Hystrixä»ç»
3.Hystrix技术指南(7)故障切换的源码unity 蛮牛项目源码运作流程原理分析(含源码)
4.springcloud2022ï¼
ribbonè´è½½å衡详解
æå¡ç«¯è´è½½åè¡¡ï¼å¨å®¢æ·ç«¯åæå¡ç«¯ä¸é´ä½¿ç¨ä»£çï¼lvs å nginxã
硬件è´è½½åè¡¡ç设å¤ææ¯è½¯ä»¶è´è½½åè¡¡ç软件模åé½ä¼ç»´æ¤ä¸ä¸ªä¸æå¯ç¨çæå¡ç«¯æ¸ åï¼éè¿å¿è·³æ£æµæ¥åé¤æ éçæå¡ç«¯èç¹ä»¥ä¿è¯æ¸ åä¸é½æ¯å¯ä»¥æ£å¸¸è®¿é®çæå¡ç«¯èç¹ãå½å®¢æ·ç«¯åé请æ±å°è´è½½å衡设å¤çæ¶åï¼è¯¥è®¾å¤ææç§ç®æ³ï¼æ¯å¦çº¿æ§è½®è¯¢ãææéè´è½½ãææµéè´è½½çï¼ä»ç»´æ¤çå¯ç¨æå¡ç«¯æ¸ åä¸ååºä¸å°æå¡ç«¯ç«¯å°åï¼ç¶åè¿è¡è½¬åã
客æ·ç«¯è´è½½åè¡¡ï¼æ ¹æ®èªå·±çæ åµåè´è½½ãRibbonã
客æ·ç«¯è´è½½åè¡¡åæå¡ç«¯è´è½½åè¡¡æ大çåºå«å¨äº æå¡ç«¯å°åå表çåå¨ä½ç½®ï¼ä»¥åè´è½½ç®æ³å¨åªéã
2ãSpring Cloudçè´è½½åè¡¡æºå¶çå®ç°
Spring Cloud Ribbonæ¯ä¸ä¸ªåºäºHTTPåTCPç客æ·ç«¯è´è½½åè¡¡å·¥å ·ï¼å®åºäºNetflix Ribbonå®ç°ãéè¿Spring Cloudçå°è£ ï¼å¯ä»¥è®©æ们轻æ¾å°å°é¢åæå¡çREST模ç请æ±èªå¨è½¬æ¢æ客æ·ç«¯è´è½½åè¡¡çæå¡è°ç¨ãRibbonå®ç°å®¢æ·ç«¯çè´è½½åè¡¡ï¼è´è½½åè¡¡å¨æä¾å¾å¤å¯¹.hutool.core.collection.CollectionUtil;
importcom.netflix.hystrix.HystrixCommandGroupKey;
importcom.netflix.hystrix.HystrixCommandKey;
importcom.netflix.hystrix.HystrixCommandProperties;
importcom.netflix.hystrix.HystrixObservableCommand;
importcom.netflix.hystrix.exception.HystrixRuntimeException;
importorg.springframework.beans.factory.ObjectProvider;
importorg.springframework.cloud.gateway.filter.GatewayFilter;
importorg.springframework.cloud.gateway.filter.GatewayFilterChain;
importorg.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
importorg.springframework.cloud.gateway.support.ServerWebExchangeUtils;
importorg.springframework.cloud.gateway.support.TimeoutException;
importorg.springframework.core.annotation.AnnotatedElementUtils;
importorg.springframework.mand;
if(CollectionUtil.isNotEmpty(apiTimeoutList)){
//requestå¹é å±äºé£ç§æ¨¡å¼
ApiHystrixTimeoutapiHystrixTimeout=getApiHystrixTimeout(apiTimeoutList,path);command=newUnicornRouteHystrixCommand(config.getFallbackUri(),exchange,chain,initSetter(apiHystrixTimeout.getApiPattern(),apiHystrixTimeout.getTimeout()));}else{
command=newUnicornRouteHystrixCommand(config.getFallbackUri(),exchange,chain,initSetter(serviceId(exchange),null));
}
returncommand;
}/
***@paramapiTimeoutList*@parampath*@return*/privateApiHystrixTimeoutgetApiHystrixTimeout(ListapiTimeoutList,Stringpath){for(ApiHystrixTimeoutapiTimeoutPattern:apiTimeoutList){
if(this.antPathMatcher.match(apiTimeoutPattern.getApiPattern(),path)){
returnapiTimeoutPattern;
}}
ApiHystrixTimeoutapiHystrixTimeout=newApiHystrixTimeout();
apiHystrixTimeout.setApiPattern("default");
apiHystrixTimeout.timeout=null;
returnapiHystrixTimeout;
}@Override
publicGatewayFilterapply(Configconfig){return(exchange,chain)-{
UnicornRouteHystrixCommandcommand=initUnicornRouteHystrixCommand(exchange,chain,config);
returnMono.create(s-{Subscriptionsub=command.toObservable().subscribe(s::success,s::error,s::success);
s.onCancel(sub::unsubscribe);
}).onErrorResume((Function)throwable-{if(throwableinstanceofHystrixRuntimeException){
HystrixRuntimeExceptione=(HystrixRuntimeException)throwable;
HystrixRuntimeException.FailureTypefailureType=e.getFailureType();switch(failureType){caseTIMEOUT:
returnMono.error(newTimeoutException());
caseCOMMAND_EXCEPTION:{
Throwablecause=e.getCause();
if(causeinstanceofResponseStatusException||AnnotatedElementUtils.findMergedAnnotation(cause.getClass(),ResponseStatus.class)!=null){
returnMono.error(cause);
}}
default:
break;
}}