长时间运行的Web服务架构
我们使用 axis2 来构建 Web 服务,并使用 Jboss 服务器来运行所有应用程序的逻辑。我们被要求构建一个与 Bean 对话的 Web 服务,该 Bean 可能需要长达 1 小时才能响应(取决于请求的大小),因此我们无法在这段时间内保持与消费者的连接打开。
我们可以使用异步 Web 服务,但效果还不是很好,因此我们决定可以实现一个 bean,该 bean 将执行 Web 服务背后的逻辑,并让服务异步调用该 bean。 Web 服务将生成一个令牌,该令牌将传递给消费者,消费者可以使用它来查询请求的状态。
我的问题是:
- 一旦我从创建该 bean 的服务中的方法返回,如何查询 Jboss 服务器上该 bean 的状态。我需要使用有状态 Bean 吗?
- 如果我想从 Web 服务端进行异步调用,我可以使用有状态 Bean 吗?
We use axis2 for building our webservices and a Jboss server to run the logic of all of our applications. We were asked to build a webservice that talks to a bean that could take up to 1 hour to respond (depending on the size of the request) so we would not be able to keep the connection with the consumers opened during that time.
We could use an asynchronous webservice but that hasn't come out all that well so we decided we could implement a bean that will do the logic behind the webservice and have the service invoke that bean asynchronously. The webservice will generate a token that will pass to the consumer and the consumer can use it to query the status of the request.
The questions I have are:
- How to I query the status of the bean on the Jboss server once I have returned from the method in the service that created that bean. Do I need to use stateful beans?
- Can I use stateful beans if I want to do asynchronous calls from the webservice side?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以采取的另一种方法是使用 JMS 和数据库。
该过程将是:
此过程对资源使用量较大,但有一些优点
Another approach you could take is to make use of JMS and a DB.
The process would be
This process is a bit heavier on resource usage, but has some advantages
我不认为有状态会话 bean 是您问题的答案,它们是为长时间运行的会话会话而设计的,这不是您的场景。
我的建议是使用 Java5 风格 ExecutorService 线程池,使用 Executors工厂类:
ExecutorService
实例。Executor
将开始在单独的线程中调用您的Callable
。Future
存储在Map
中,并以令牌作为密钥。Future
:令牌,并在Future
上调用get()
,并设置超时值,以便它只等待很短的时间来获取答案。get()
调用将返回任何Callable
调用的执行结果。Future
。这是一个非常稳健的方法。如果您愿意,您甚至可以配置 ExecutorService 来限制可以同时执行的调用数量。
I don't think stateful session beans are the answer to your problem, they're designed for long-running conversational sessions, which isn't your scenario.
My recommendation would be to use a Java5-style ExecutorService thread pool, created using the Executors factory class:
ExecutorService
instance.Callable.call()
method would make the actual invocation on the business logic bean, in whatever form that takes.Callable
is passed toExecutorService.submit()
, which immediately returns aFuture
object representing the eventual result of the call. TheExecutor
will start to invoke yourCallable
in a separate thread.Future
in aMap
with the token as the key.Future
using the token, and callsget()
on theFuture
, with a timeout value so that it only waits a short time for the answer. Theget()
call will return the execution result of whatever theCallable
invoked.Future
from the `Map.It's a pretty robust approach. You can even configure the
ExecutorService
to limit the number of calls that can be in execution at the same time, if you so desire.