长期运行的网络服务架构 [英] Long running webservice architecture

查看:18
本文介绍了长期运行的网络服务架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用axis2 来构建我们的网络服务和一个Jboss 服务器来运行我们所有应用程序的逻辑.我们被要求构建一个与 bean 对话的网络服务,该服务可能需要长达 1 小时的响应时间(取决于请求的大小),因此在此期间我们无法保持与消费者的连接.

我们可以使用异步 Web 服务,但效果并不理想,因此我们决定实现一个 bean,该 bean 将执行 Web 服务背后的逻辑并让服务异步调用该 bean.Web 服务将生成一个令牌,该令牌将传递给消费者,消费者可以使用它来查询请求的状态.

我的问题是:

  1. 从创建该 bean 的服务中的方法返回后,如何在 Jboss 服务器上查询该 bean 的状态.我是否需要使用有状态 bean?
  2. 如果我想从 Web 服务端进行异步调用,我可以使用有状态 bean 吗?

解决方案

您可以采取的另一种方法是使用 JMS 和数据库.

过程是

  1. 在 Web 服务调用中,将消息放入 JMS 队列
  2. 将一条记录插入到数据库表中,并将该记录的唯一 ID 返回给客户端
  3. 在侦听队列的 MDB 中,调用 bean
  4. 当 bean 返回时,更新数据库记录为完成"状态
  5. 当客户端调用状态时,读取数据库记录,根据记录返回未完成"或完成".
  6. 当客户端调用并且记录显示完成"时,返回完成"并删除记录

这个过程在资源使用上有点重,但有一些优点

  • 如果您的 bean 方法抛出异常,则持久 JMS 队列将重新传递
  • 如果您的服务器重新启动,持久 JMS 队列将重新传送
  • 通过使用数据库表代替一些静态数据,您可以支持集群或负载均衡环境

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:

  1. 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?
  2. Can I use stateful beans if I want to do asynchronous calls from the webservice side?

解决方案

Another approach you could take is to make use of JMS and a DB.

The process would be

  1. In web service call, put a message on a JMS Queue
  2. Insert a record into a DB table, and return a unique id for that record to the client
  3. In an MDB that listens to the Queue, call the bean
  4. When the bean returns, update the DB record with a "Done" status
  5. When the client calls for status, read the DB record, return "Not Done" or "Done" depending on the record.
  6. When the client calls and the record indicates "Done", return "Done" and delete the record

This process is a bit heavier on resource usage, but has some advantages

  • A Durable JMS Queue will redeliver if your bean method throws an Exception
  • A Durable JMS Queue will redeliver if your server restarts
  • By using a DB table instead of some static data, you can support a clustered or load balanced environment

这篇关于长期运行的网络服务架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆