简体   繁体   English

忽略Web服务单向操作的HTTP响应

[英]Ignoring HTTP response for web service one-way operation

I am developing a jax-ws webservice that pushes messages asynchronously to the subscribed consumers using one-way operation. 我正在开发一个jax-ws Web服务,该服务使用单向操作将消息异步地推送到订阅的使用者。

Unfortunatelly with each notification, server awaits a HTTP202 response confirmation which blocks the thread for a fraction of a second. 不幸的是,每次通知时,服务器都会等待HTTP202响应确认,该确认将线程阻塞一秒钟。 This is affecting the performance of the system and I am looking for a way around this. 这正在影响系统的性能,我正在寻找解决方法。

Is there any way to execute a web-service one-way call and ignore the HTTP response status? 有什么方法可以执行Web服务单向调用并忽略HTTP响应状态?

Ok, so after spending a lot of time on this I have found two solutions: 好的,因此在花了很多时间之后,我找到了两种解决方案:

1) Using Apache HTTPComponents, which provide AsyncHTTPClient with nice API allowing us to build a HTTP response from the scratch. 1)使用Apache HTTPComponents,它为AsyncHTTPClient提供了不错的API,使我们能够从头开始构建HTTP响应。

2) More web-service oriented solution based on Apache CXF platform (which includes the HTTPClient implementation) - first we need to set the global Bus property: 2)更多基于Apache CXF平台(包括HTTPClient实现)的面向Web服务的解决方案-首先,我们需要设置全局Bus属性:

Bus bus = BusFactory.getDefaultBus();
bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);

Then, we use custom interceptor to set the message exchange property to asynchronous: 然后,我们使用自定义拦截器将消息交换属性设置为异步:

final class SkipWaitInterceptor extends AbstractSoapInterceptor {

    SkipWaitInterceptor() {
        super(Phase.SETUP);
    }

    @Override
    public void handleMessage(final SoapMessage message) throws Fault {
        message.getExchange().setSynchronous(false);
    }

}

Finally, we register the interceptor on our asynchronous Endpoint 最后,我们在异步端点上注册拦截器

org.apache.cxf.endpoint.Client client =
                org.apache.cxf.frontend.ClientProxy.getClient(this.notificationConsumer);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
cxfEndpoint.getOutInterceptors().add(new SkipWaitInterceptor());

That's all, one-way operation responses no longer block the communication. 仅此而已,单向操作响应不再阻止通信。

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

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