Monday, October 20, 2008

Callback on ESB

Invoking a service asynchronously is something which is very often in a real world systems and scenarios. ESB allows both synchronous and asynchronous invocation, but all the articles and documentation available tells only about one way asynchronous invocation. At first, it appears that since ESB is stateless, it cannot hold the context and hence callback is not achievable. Implementation of this case gives the understanding that context handling is the task of bpel and not the ESB's. In this post let's look at how to invoke a service connected to an ESB in an asynchronous manner and then getting the response back via callback.

Scenario -
An async BPEL process 1 will invoke a routing service of ESB. Routing service calls the SOAP service on async BPEL process 2. This process then callback the route to BPEL process 1 on ESB (Routing Service --> process 1 SOAP service --> process 1).



Modify the client process wsdl to add a new operation as shown in image. This will be the operation which will be plugged to ESB as a soap service.

Create a routing service RS_In with its own interface/wsdl created by the routing service wizard. Also attach the service bpel to ESB by adding soap service. The routing service and soap service will now look like the one shown in image below.

Register the project to ESB.

Create a partner link of RS_In in client process, connect it with invoke. Add a receive activity below for the callback operation 'submitStockQuote' and connect it to the 'client' partner link. The final client bpel will look like -


Now create another routing service RS_Out and soap service to connect the service bpel to ESB. Connect the routing service with operation 'submitStockQuote' of the soap service. Final ESB project will look like -

Register the project to ESB.

Create a partner link of routing service RS_out in service bpel and associate it with the receive activity 'callbackClient'. The service bpel is as shown in image below.


The only thing remain here is correlation. Correlation is required at bpel and not at ESB. So create a new correlation set and assign it to invoke and receive of the client bpel. Following artifacts where created or modified while creating and assigning correlation.

processname_properties.wsdl

processname.bpel

processname.wsdl

Test and run the client bpel, two instances of ESB gets created as shown below -