简体   繁体   English

Spring Cloud:如何在Zuul网关中为Hystrix定义默认回退?

[英]Spring Cloud: How to define default fallback for Hystrix in Zuul gateway?

I am using Spring Cloud Brixton.M3 and Spring Boot 1.3.0.RELEASE. 我正在使用Spring Cloud Brixton.M3和Spring Boot 1.3.0.RELEASE。 I am sort of new in this (especially in Spring Cloud). 我在这方面有点新鲜(特别是在Spring Cloud中)。 I have created Registry Server (ie Eureka instance), Config server and Gateway. 我创建了Registry Server(即Eureka实例),Config服务器和Gateway。
As per my requirement I am intercepting each request hitting the gateway in one of my Filter to extract required information from Header and based upon that I am throwing exception or forwarding / verifying that request using Feign Client . 根据我的要求,我拦截每个请求到达我的一个过滤器中的网关,以从Header中提取所需信息,并根据我抛出异常或使用Feign Client转发/验证该请求。 Some time hystrix throw HystrixRuntimeException when it couldn't reach out to respective services or because of any other issues. 有些时候hystrix在无法访问相应服务或因任何其他问题时抛出HystrixRuntimeException

So What I want is: 所以我想要的是:

  1. Provide default fallback method for every forwarding request, so that I can read and process it accordingly. 为每个转发请求提供默认回退方法,以便我可以相应地读取和处理它。
  2. Global Exception handling other than @ControllerAdvice since I am not providing any custom @HystrixCommand and Controller to call services (AOP based solution ?). 除了@ControllerAdvice之外的全局异常处理因为我没有提供任何自定义的@HystrixCommand和Controller来调用服务(基于AOP的解决方案?)。
  3. Is it possible to intercept every failed request and retry them for certain number of times ? 是否有可能拦截每个失败的请求并重试它们一定次数? Internally it might be happening but can I override this functionality and handle each failed request either because of TimedOutException or because of HttpConnectionPool exception ? 在内部它可能正在发生,但我可以覆盖此功能并处理每个失败的请求,因为TimedOutException或HttpConnectionPool异常?

Update 更新
Is it a good practice to provide own routing in Zuul gateway ? 在Zuul网关中提供自己的路由是一种好习惯吗? using @RestController and @HystrixCommand together ? 一起使用@RestController@HystrixCommand (I think its a bad idea, because over the period of time we will end up with lots of controllers and hence actual use of intelligent routing wouldn't work as expected) (我认为这是一个坏主意,因为在一段时间内我们最终将会有大量的控制器,因此实际使用智能路由将无法按预期工作)

Currently there is an open issue for fallbacks with feign. 目前存在一个悬而未决的问题 There is also an open issue for fallbacks with zuul. 还有一个与zuul回退的公开问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM