spring cloud gateway集成hystrix全局断路器
程序员文章站
2022-07-15 12:58:21
...
pom.xml添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
在配置文件中,增加spring.cloud.gateway.default-filters:
default-filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallbackcontroller
如上的配置,将会使用HystrixCommand打包剩余的过滤器,并命名为fallbackcmd,我们还配置了可选的参数fallbackUri,降级逻辑被调用,请求将会被转发到URI为/fallbackcontroller的控制器处理。定义降级处理如下:
@RequestMapping(value = "/fallbackcontroller")
public Map<String, String> fallBackController() {
Map<String, String> res = new HashMap();
res.put("code", "-100");
res.put("data", "service not available");
return res;
}
此时可以设置hystrix超时时间(毫秒) ,默认只有2秒
default-filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/fallbackcontroller
上一篇: iOS开发 解决Xcode9的Log日志无法输出中文的问题
下一篇: 在Spring Cloud中配置Feign的拦截器 增加自定义的请求信息进去 以及演示加入Authorization到请求Headers
推荐阅读
-
spring cloud gateway集成hystrix全局断路器
-
spring cloud 入门系列四:使用Hystrix 实现断路器进行服务容错保护
-
Spring Cloud Hystrix断路器(四)
-
Spring Cloud Gateway网关集成Swagger2.9.2 设置全局token
-
spring cloud gateway集成hystrix全局断路器操作
-
Spring Cloud Gateway Hystrix fallback获取异常信息的处理
-
微服务实战——Spring Cloud + Zuul Gateway + Eureka集成
-
spring cloud gateway集成hystrix实战篇
-
Spring Cloud实战 | 最终篇:Spring Cloud Gateway+Spring Security OAuth2集成统一认证授权平台下实现注销使JWT失效方案
-
Spring Cloud Gateway的动态路由怎样做?集成Nacos实现很简单