可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I need to create a async webservice using cxf with java first approach. But i am unable to
find any web resource/ website which tells me how to do this?
Can you please tell how can I write a async webservice using CXF with java first approach?
Thanks
Shekhar
回答1:
A simple alternative that can work in many situations:
- Execute a normal web service from the client.
- On the server, start the job in a new thread and return with a status like "job started"
- When the job is finished, let the server send the result back to the client.
Advantages:
- It's simple!
- You get a quick result that tells if the job is accepted.
Disadvantages:
- Both the client and server must listen for incomming web services.
- Often requires an id handling to match the result with the original task.
回答2:
Use a messaging infrastructure like ActiveMQ behind your webservice - get the webservice request normally, take the request message and post it to an inbound queue in ActiveMQ and respond with an acknowledgement synchronously. Process the inbound queue using some batch infrastructure (batch jobs, listeners on Queue etc) and then once processing is complete, either post a completion back to the caller - either using the messaging infrastructure or in conjunction with DB.