0

As part of a web-service say A, I need to call another web-service say B.

The response given to the caller of A shouldn't be dependent upon B i.e it should be returning the response back to the caller irrespective of the outcome of B, considering that B might take some time.

The systems calling A and B are both different. How do I achieve this?

Note: Using RESTful web-services/Java

Chillax
  • 4,418
  • 21
  • 56
  • 91
  • Remember that, in the end, the web service operation in programming language will be a plain method for your client, so use it within an asynchronous call. Check [How to asynchronously call a method in Java](http://stackoverflow.com/q/1842734/1065197). – Luiggi Mendoza Mar 27 '13 at 13:18

3 Answers3

3

The client should invoke the Web Service A operation asynchronously.

Web Service A should invoke the Web Service B operation asynchronously as well.

With this, the client will always receive a response regardless of the outcome of Web Service B.

Most of the REST frameworks already have asynchronous invocation support:

Jops
  • 22,535
  • 13
  • 46
  • 63
0

If you don't mind 3rd party libs use jetty-client: http://www.supermind.org/blog/1023/non-blocking-nio-http-requests-in-java-with-jettys-httpclient

Here is maven package description: http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-client

Jarosław Jaryszew
  • 1,414
  • 1
  • 12
  • 13
0

As per given requirement,

Call from Client to Service A can be synchronous Restful call in your case. Call from Service A to Service B is asynchronous.

So use restful connectivity between client to Service A as usual.

In case of Call Service A -> Service B you need to use, JMS concepts, say request and response queues. Please refer http://docs.oracle.com/cd/E14571_01/web.1111/e15184/asynch.htm These are generally implemented as 2 one way requests.

Chakradhar K
  • 501
  • 13
  • 40