本文建立在spring-cloud-zuul环境搭建的基础上进行扩展介绍。
介绍
zuul支持路由到客户端进行重试,通过spring-retry 实现, 系统默认是不允许重试的,如果开启重试客户端则需要支持请求的幂等性
Zuul 服务
maven依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
配置
spring:
application:
name: zuul
cloud:
loadbalancer:
retry:
enabled: true #负载均衡启动重试
zuul:
routes:
server:
path: /server/**
serviceId: server
retryable: true #是否开启重试功能
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 6000
ribbon:
ConnectTimeout: 1000
ReadTimeout: 1000
MaxAutoRetries: 2 #对当前服务的重试次数
MaxAutoRetriesNextServer: 1 #切换相同Server的次数
OkToRetryOnAllOperations: true # 对所有请求都重试