使用 Hystrix 包装 SOAP 调用 (WebServiceGatewaySupport)

wrap a SOAP call (WebServiceGatewaySupport) with Hystrix

我正在尝试找出一个将 hystrix 与 SOAP 调用结合使用的示例,并且我可以找到与 REST 相同的所有示例。

从 hystrix 文档来看,这似乎是可行的,如果你能给我指出一个有用的例子。

此外,如果有任何更好的方法在 REST 和 SOAP 调用之间建立一致的断路器(可能扩展到 EJB)。

您可以通过创建一个扩展 HystrixCommand 的内部 class 然后覆盖 运行() 方法来做到这一点。

public class webServiceClient extends WebServiceGatewaySupport {
public Response callsoap(Request request) {
    SoapCommand sfc = new SoapCommand(getWebServiceTemplate(), request, 
            soapRequestHeaderModifier, configuration);
    return  sfc.execute();
}

class SoapCommand extends HystrixCommand<Response>{
    public SoapCommand() {
        super(HystrixCommandGroupKey.Factory.asKey("example"));
    }
    @Override
    protected Response run() {
        return (Response) webServiceTemplate.marshalSendAndReceive(configuration.getUri(), 
                request, soapRequestHeaderModifier);
    }
    //fallback method goes here
}

}