我们通过直接扩展 HystrixCommand 类来使用 Hystrix 功能。但是对于一些业务异常,正在触发Hystrix的fallback方法。
我不想为某些特定于业务的异常触发 Hystrix 回退。如果不基于注释,我如何实现它?
最佳答案
使用 ignoreExceptions 注解参数
@HystrixCommand(ignoreExceptions = { BaseException.class, MissingServletRequestParameterException.class, TypeMismatchException.class })
参见 https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica#error-propagation
我看到您正在扩展 HystrixCommand 而不是使用注释,但这没关系,只需在命令中设置该属性,它应该具有相同的效果。
不幸的是,Hystrix 命令是由构建器模式创建的,因此您将不得不进行一些修改。在 HystrixCommandBuilder 中使用的 DefaultProperties.java 中添加了 ignoreExceptions
关于java - Hystrix命令中的一些异常如何说Hystrix不触发fallback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44247070/