I have an asynchronous web service pair that I need to handle in the web layer. I have written a ‘request’ service client that sends a query request to a service. The client receives an http ‘200’ that the message was successfully received by the server.
I then have a separate response listener which is a Camel/CXF web service which receives the response. I am using a WS-Addressing message ID to correlate the requests and responses.
I am now tasked with handling this in the web layer. I would like the user to complete a form, click submit, and invoke the web service. Then my CXF web service listener would receive a response, look at the Message ID and return it to the web layer.
With a synchronous service, this is very straight forward to do. However, with the asynchronous web service pair, I am not sure where to start. I could use a polling approach where I invoke the web service, write the message ID to a map and then poll the map and wait for the web listener to write the response to the map. However, I think there are frameworks that support this.
I am research Spring MVC and JQuery as I think this is the right direction but am having problems finding good resources for beginners.
Does anyone have any ideas?
Thanks,
Yogesh
One approach is to write a Spring MVC controller that invoke outbound web service, and wait until the inbound web service (ie: response) is received. You can achieve this by suspending your thread while waiting inbound service, and resuming the thread afterwards. While this is happening, you can show some sort of spinner on the website. So from browser perspective, it’s still look like one request and response.
However depending on your website traffic, this could be an inefficient approach because one web container thread will be utilized while you wait for the inbound service. If your website has heavy traffic — and the delay between inbound and outbound requests are significant, you can run out of free threads quick and crashes the site.