HystrixFeign 클라이언트가 있는데 대체물에 대한 이유를 알고 싶기 때문에 fallback 구현에서 원인/예외를 얻으려고합니다. 그 이유를 해결할 수있는 이유는 무엇입니까? 서비스 호출에 실패했습니다. 그러나 아래 구현은 원인을 얻지 못합니다. 이것은 정상적으로 작동하며 폴백은 항상 호출됩니다. 그러나 나는 단서가 없다. 나는 Feign과 Hystrix에 처음 온 사람입니다. 내 응용 프로그램은 Java 1.6 년 전으로 작성되었으며 이것은 향상된 호출의 일종입니다. 그래서 나는 어떤 람다 식으로도 갈 수 없다.HystrixFeign 클라이언트 대체에서 원인을 얻는 데 문제가 발생했습니다.
나는
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;
}
}
}