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

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

问题描述

我们使用axis2构建我们的Web服务,并使用Jboss服务器来运行所有应用程序的逻辑.我们被要求构建一个与Bean进行通信的Web服务,该服务最多可能需要1个小时才能做出响应(取决于请求的大小),因此我们将无法在该时间内保持与消费者的连接打开.

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

我的问题是:

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

解决方案

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

该过程将是

  1. 在Web服务调用中,将消息放在JMS队列中
  2. 将记录插入数据库表中,并将该记录的唯一ID返回给客户端
  3. 在侦听队列的MDB中,调用Bean
  4. 当bean返回时,以完成"状态更新数据库记录
  5. 当客户要求状态时,请读取数据库记录,并根据记录返回"Not Done"或"Done".
  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

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

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