我有HystrixFeign客户,我试图让事业/异常在我的候补执行,因为我真的想知道回退的原因,所以我可以解决,为什么服务呼叫失败的问题。 但是,下面的实现并不让我的事业。 这只是正常和备用获取调用所有的时间。 但我不知道为什么。 我是新来假装和豪猪。 我的应用程序是用Java 1.6的。几年前,这是一种增强的调用。 所以我不能去任何lambda表达式。
我已经定义像下面的客户端界面
public interface MyServiceFeignClient {
@RequestLine("POST /myService/order")
@Headers("Content-Type:application/vnd.org.company.domain.order+json;version=1.0")
ServiceResponse sendOrder(String content);
}
我FeignClientFacory就像下面
public class FeignClientFactory {
private static final Logger LOG = LoggerFactory.getLogger(FeignClientFactory.class);
private String serviceUrl;
public FeignClientFactory(final String serviceUrl) {
this.serviceUrl = serviceUrl;
}
public MyServiceFeignClient newInstance() {
return HystrixFeign.builder()
.decoder(new GsonDecoder())
.target(MyServiceFeignClient.class, serviceUrl);
}
class ClientFallbackFactory implements MyServiceFeignClient, FallbackFactory<ClientFallbackFactory> {
final Throwable cause;
public ClientFallbackFactory() {
this(null);
}
ClientFallbackFactory(Throwable cause) {
this.cause = cause;
}
// note that this method is not getting called at all
@Override
public ClientFallbackFactory create(Throwable cause) {
if (cause != null) {
String errMessage = StringUtils.isNotBlank(cause.getMessage()) ? cause.getMessage() : "unknown error occured";
LOG.debug("Client fallback called for the cause : {}", errMessage);
}
return new ClientFallbackFactory(cause);
}
// everytime this method is called as fallback and the cause is just null
@Override
public ServiceResponse sendOrder(String content) {
LOG.debug("service client api fallback called");
ServiceResponse response = new ServiceResponse();
String errMessage = (cause == null ? "service client api fallback called" : cause.getMessage());
response.setErrorMessage(errMessage);
response.setResultStatus("WARN");
return response;
}
}
}