简体   繁体   中英

Asynchronous call from java web service to .net application

Scenario :

There is a java library that helps asynchronously listen to some system events. I am planning to use the already implemented asynch functionality from a vb.net project. I have planned to address it in the following way :

  1. Write a web service around the java library

  2. Add reference of that service to the .net app.

  3. The web service will run locally on a tomcat as the .net app. The problem i am faced with is how do i make the web service communicate to the .net app asynchronously ? Should the .net app block and wait on a web service and if so how ?

I believe that firstly you need a design pattern for asynchronous services communication t better address your system requirements.

1 - Asynchronous Response Handler

The application creates a separated thread to process server response leaving main thread free for other tasks. When response arrives main thread is notified to receive the response. There are two implementation strategies: pooling and callback. With pooling, the main thread checks for response in the second thread until the response is available. With callback, the second thread notifies the main thread using a callback method.

2 - Request/Acknowledge

This patterns is based on the server participation to achieve asynchronous communication. Instead of splitting the process into two client threads, the process divided into two different transactions between client and server. This patterns needs some kind of correlation identification to associate request and response transactions. A messaging subsystem is used to achieve more scalability and availability.

A simple solution could be implemented using Asynchronous Response Handler/Callback Strategy. To do that, the service provider (java) could be a simple jax-ws web service.The service consumer(.net) implementation could use the AsyncCallback Delegate. There is a example here .

References:

http://www.servicedesignpatterns.com/WebServiceInfrastructures/AsyncResponseHandler http://www.servicedesignpatterns.com/ClientServiceInteractions/RequestAcknowledge http://msdn.microsoft.com/pt-br/library/system.asynccallback(v=vs.110).aspx (AsyncCallback Delegate) http://msdn.microsoft.com/en-us/library/wyd0d1e5(v=vs.100).aspx (service consumer) http://java.dzone.com/articles/jax-ws-hello-world (service producer)

You are planning to build a long running process, consider using some workflow engine like JBPM or Activiti. Since your calls are going to be web services which are stateless & you intend to have callbacks better would be an option to create persistent long running workflows since they would take care of most of the design & architectural issues else you would end up handling it. eg of issues -Corelation between request-response -Loss of data on reboot of system -Application getting overwhelmed with data synchronization.

Polling & calbacks are just mechanisms for inter process communication but you need to handle req-resp correlation as well as ensure reliablity in the communication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM