简体   繁体   中英

How to implement one-way operation in Java Web Services?

How to implement one-way operation in Web Services (using Java or Spring annotations)?

I have tried to add one way as given below

   @WebService
   public interface DanduServices {
     @Oneway
     public void saveDanduInformation(@WebParam(name = "serv") ServDTO Serv, @WebParam(name = "dandu") DanduDTO danduDto);

but it is still request-response not asynchronus or one way.

Could anyone suggest to make a operation one-way in service endpoint and let other operations behave as per request-response?

You need to think in terms of the protocol as well though. In HTTP when you send a request you wait for a response, if no response comes back after an amount of time then you will receive a time-out error. So when you talk about one-way (you should rather say async request maybe) you really need to specify exactly what you mean. Do you want to have confirmation that your message was received ie have the server respond back with an OK status code and go off and complete it's task but you not wait for the task to be completed? Then you would need to spawn another thread. Spring has AOP for this the same way it has for transactions with @Transactional . Instead you annotated your method with @Async and return a Future<Something> . You'll also need @EnableAsync in your config. Refer to this article for an example Hot To Do @Async

If you don't even care about if the server received your request you don't want to use TCP/HTTP but instead UDP which is used in VOIP (phone over internet) for instance and is quicker, but it will depend on your client.

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