aspose file tools*
The moose likes Web Services and the fly likes Sync or Async Web Service? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Sync or Async Web Service? " Watch "Sync or Async Web Service? " New topic
Author

Sync or Async Web Service?

Jack Delerousse
Greenhorn

Joined: Nov 11, 2008
Posts: 4
I'm putting together a web service which will accept a batch of XML, which could be pretty big, and put it onto a queue for processing.

It's turning out to be a bit more complicated than I originally hoped. A synchronous service would be easiest, and simplest, but what are the chances of timing out? I'm not sure. So, I have been planning on an asynchronous service, to play it safe.

For an asynchronous service, Axis2 relies on WS-addressing, which could have firewall issues, per this post from Peer Reynders at http://www.coderanch.com/t/224525/Web-Services/java/Asynchronous-Web-services-with-Axis.

Peer suggested in that post that using a non-blocking client might work, but that again poses the timeout issue.

Finally, to defeat the timeout problem, he suggests using a correlation identifier, which means that the initial request is assigned an id which is returned to the client. and have the client poll for the result, using the id. A message handler to designed to ignore overly aggressive client polls made within some threshold interval could be added ref http://www.ibm.com/developerworks/webservices/library/ws-asynch2/#4

But, if I configure the service to be asynchronous, then it will create a separate thread to do the processing - including writing to the queue. This would lessen the chances of a timeout, correct?

For the acknowledgment, I could use a correlation identifier/batch number, and maybe send an email to the client. I could get the email from the data itself, or maybe I could look it up on for the customer locally. I don't necessarily even need to send the client an acknowledgment, but it would probably be a good idea.

Does this make sense? In other words, I need to make this service asynchronous to lessen the risk of a timeout, right?








Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1174
Jack,

An interesting article about the subject at Working With Asynchronous .NET Web Service Clients.

Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Jack Delerousse wrote:
But, if I configure the service to be asynchronous, then it will create a separate thread to do the processing - including writing to the queue. This would lessen the chances of a timeout, correct?

With reservations for not having completely understood the entire question, here are my thoughts:
The separate thread that processes the request to the web service only inserts the data received, that is the batch data, into a queue. The first step of processing the request is then done and the web service can now return a correlation identifier or such to the client.
Some time later, another thread, constantly running in the background, retrieves data from the queue and processes it.
Finally the processed data, with some association to the correlation identifier, is made available to the (other) web service operation which the client uses to poll for result data.
Reference:
http://java.sun.com/blueprints/guidelines/designing_webservices/html/architecture5.html#1147022

Does this make sense? In other words, I need to make this service asynchronous to lessen the risk of a timeout, right?

Yes, to me, this makes sense.

An alternative that I come to think of is to do SOAP over email. The client mails the request, with the batch data, to some mail address. The email is then processed by the service and, using for instance the reply-to email address, sent back to the client.

If using SOAP is not written in stone, another alternative is a RESTful web service that, as a result of POSTing the batch data, returns an URL at which the client can poll for the result.
Update: Just discovered that JBoss RESTeasy already has built-in support for this kind of asynchronous operations.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sync or Async Web Service?