简体   繁体   English

如何在Jboss集群中实现此队列?

[英]How to implement this Queue in a Jboss cluster?

my application works as a middle ware, receiving requests from clients, then transforming it in certain logic and sending the transformed requests to another service provider as normal HTTP requests or Webservice soap requests. 我的应用程序用作中间件,接收来自客户端的请求,然后以某种逻辑对其进行转换,并将转换后的请求作为常规HTTP请求或Webservice soap请求发送给另一服务提供者。 The application was deployed on two jboss servers (in cluster) behind a load balancer. 该应用程序已部署在负载均衡器后面的两个jboss服务器(群集中)中。

let's say my application is A, the service provider is S. 假设我的应用程序是A,服务提供商是S。

Now i am informed that, every year S will be down several (3-5) times. 现在我被告知,每年S将下降几(3-5)倍。 Each down time will last about 4 hours. 每个停机时间将持续约4个小时。 I can get a schedule about the down time. 我可以得到有关停机时间的时间表。

During the downtime, A should not transform and send request to S any longer, but put received requests in a Queue. 在停机期间,A不应再转换并向S发送请求,而应将接收到的请求放入队列中。 After S is back, the requests in the queue should be processed. S返回后,应处理队列中的请求。

Note: 注意:

  1. The requests A received must be processed in exact order as they came.One by one. 收到的请求A必须按照发出的确切顺序进行处理。 Processing a request means A sending transformed requests to S, and getting the response success or error. 处理请求意味着A将转换后的请求发送到S,并获得响应成功或错误。 usually this won't take much time. 通常这不会花费很多时间。

  2. Base on 1, when A is working on queued requests, new incoming requests should be enqueued, although S is already available. 基于1,当A处理排队的请求时,尽管S已经可用,但新的传入请求应排队。 until the queue is empty, A can continue sending request directly to S. 直到队列为空,A可以继续直接向S发送请求。

  3. Every minute A receives 2-3 requests. A每分钟收到2-3个请求。

Since we have two Jboss, I planed to maintain this Queue in Database, threads working on queue and managing the Downtime status. 由于我们有两个Jboss,因此我计划在数据库中维护该队列,在队列中工作的线程并管理停机时间状态。 However, the synchronization between two jboss always makes me headache. 但是,两个jboss之间的同步总是让我头疼。

shortly, the problems I met were: 不久,我遇到的问题是:

  • how to set the down time flag, so that the two jboss do the request enqeue, instead of sending. 如何设置停机时间标志,以便两个jboss进行请求请求,而不是发送请求。 (solution i thought was, before processing each request, query database for this flag. The flag was set by thread. it might be the worse solution.) (我认为解决方案是,在处理每个请求之前,请向数据库查询此标志。该标志是由线程设置的。这可能是较差的解决方案。)

  • after S is back, how to design the Dequeue operation of two jboss. S返回后,如何设计两个jboss的出队操作。 (it seems that, same time, there is always one jboss is idle... ) (似乎同时有一个jboss总是闲着……)

  • how to inform two jboss," now the queue is empty, don't do enqueue any longer." 如何通知两个jboss,“现在队列为空,不再排队。”

The logic is a bit complicated. 逻辑有点复杂。 I hope I explained my problem clearly... 我希望我能清楚地解释我的问题...

Do you guys have any idea on that? 你们有什么想法吗?


Some more description about the FIFO. 有关FIFO的更多说明。 If there was no downtime, A can process those requests from different clients in parallel. 如果没有停机时间,A可以并行处理来自不同客户端的那些请求。 Because this 'transaction-liked' order is ensured by the clients. 因为客户保证了这种“类似交易”的订单。 for example. 例如。

client x :
-send http://..../createUser...
-received 'success' from A
-send http://../updateUser...
-received 'success' from A

if createUser() failed, the updateUser is not gonna be sent. 如果createUser()失败,则不会发送updateUser。

client y:
-send http://.. createCompany...

Given that there was another client (y) sending request createCompany at same time as x.createUser. 假设有另一个客户端(y)与x.createUser同时发送请求createCompany。 these two requests can be processed by A in parallel. 这两个请求可以由A并行处理。

Once thinking about the downtime and the queue: 在考虑停机时间和队列之后:

-send http://..../createUser...
(downtime)
-received 'enqueue'
(S is back)
-send http://../updateUser...

now the order "create->update" needs to be ensured by A, not clients. 现在,需要由A(而不是客户端)确保“创建->更新”的顺序。


Thanks in advance! 提前致谢!

Kent 肯特

Do you get any acknowledgements from S that a specific request was properly received? 您是否从S收到确认已正确收到特定请求的任何确认? (If not, you should consider implementing this to make your app more robust, and minimise the chances of losing requests due to network problems, server crashes etc.) (如果没有,则应考虑实施此方法,以使您的应用程序更强大,并最大程度地减少由于网络问题,服务器崩溃等导致丢失请求的机会)

Such an acknowledgment mechanism could be enhanced with an algorithm of using increasing timeouts in case an ACK is not received in time after sending a request. 在发送请求后未及时收到ACK的情况下,可以通过使用增加超时的算法来增强这种确认机制。 Ie if the ACK is not received within a configured timeout interval t, the request is resent. 即,如果在配置的超时间隔t内未收到ACK,则重新发送该请求。 The next time there is a bigger timeout, eg 2*t, then 4*t etc. As long as the actual request is not acknowledged, incoming newer requests are queued. 下次会有更大的超时,例如2 * t,然后是4 * t等。只要未确认实际请求,就会将传入的较新请求排队。 Once the actual request is successfully transmitted, the queued requests are processed in FIFO order. 成功发送实际请求后,将按FIFO顺序处理排队的请求。 If the queue is empty, normal processing is resumed. 如果队列为空,则恢复正常处理。

This algorithm would automatically handle scheduled downtimes of S as well as any other network failures etc. at the price of somewhat more processing and network traffic. 该算法将自动处理S的计划内停机时间以及任何其他网络故障等,其代价是更多的处理和网络流量。 But with 2-3 requests per minute, this should not be a concern (unless individual requests are huge, of course). 但是,每分钟2-3个请求就不必担心了(当然,除非单个请求很大)。

Of course, it could even be improved to make the default timeout configurable by time periods. 当然,甚至可以对其进行改进,以使默认超时可以按时间段进行配置。 Ie for the duration of a scheduled downtime of 4 hours, the default timeout could be set to 4 hours. 即,在计划的4个小时的停机时间内,可以将默认超时设置为4个小时。 Once the downtime is over, the timeout is reset to the default value. 停机时间结束后,超时将重置为默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM