Thursday, September 25, 2008

Asynchronous Web Service Invocations with Axis2

If we use an Axis2 client for Web service invocations, we have the luxury of having asynchrony at two different levels. One option is to have asynchrony at the client level and the other is to have it at the transport level. Using combinations of these two options, we can go for different levels of asynchrony.

On the client side, we achieve asynchrony using callbacks. Here what happens is that the service invocation thread does not get blocked and upon reception of the response, the callback function gets notified by the framework. So, the client's invocation thread is free to keep sending requests.

This is how we use callbacks on the client side to achieve synchrony.

1. Create callback object
2. Send request
3. Wait on the callback

Look at the following Axis2/C sample for exact syntax of these steps.

callback

At the transport level we achieve asynchrony using a separate listener for the response. So, as soon as the request message is sent, the transport sender returns without waiting for the response on the same thread. But the request message carries the EPR of the listener service that is waiting for the response so that the target Web service can use that EPR to send the response back. This EPR address is sent in the ReplyTo SOAP header of the request message. It is needless to say that we make use of the Addressing module (WS-Addressing) of Axis2.

And this is how we tell Axis2 that we need asynchrony at the transport level.

1. Tell the framework that we need a separate listener
2. Set EPR of this listener in ReplyTo header of request
3. Send request and receive response

Look at the following Axis2/C sample for exact syntax of these steps.

sep_listener

0 comments: