简体   繁体   中英

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.

Unfortunatelly with each notification, server awaits a HTTP202 response confirmation which blocks the thread for a fraction of a second. 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?

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.

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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