Wildfly JMS:当消息存在时,MDB bean空闲 [英] Wildfly JMS: MDB beans idle when messages exist

查看:126
本文介绍了Wildfly JMS:当消息存在时,MDB bean空闲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Wildfly 8.1(HornetQ)上使用捆绑的JMS实现来对大量文档进行OCR。

I am using the bundled JMS implementation on Wildfly 8.1 (HornetQ) to OCR a large number of documents.

我想要一个包含3个MDB的池来消耗包含要被OCR的文档的队列的消息。每个MDB都使用 Apache commons-exec 启动一个进程并阻塞,直到该进程退出。

I want to have a pool of 3 MDBs consuming the messages of a Queue with the documents to be OCRed. Each MDB starts a process with the Apache commons-exec and blocks until that process exits.

在我的测试中,我有50条JMS消息(每条消息代表一个要被OCR的文档),它们在测试开始时加载到队列中。处理开始时,在任何给定时间我都可以看到有3个CPU密集型OCR进程,一个由每个MDB启动和阻止。在某些时候,在20分钟左右之后,其中一个OCR过程消失,并且在任何给定时间只有2个保持活着。当剩下10条JMS消息时,另一个OCR进程停止,并且在任何给定时间只有1条。

In my test I have 50 JMS messages (each represents a document to be OCRed) which are loaded on the Queue at the beginning of the test. When the processing starts, at any given time I can see that there are 3 CPU intensive OCR processes, one started and blocked upon by each MDB. At some point, after 20 minutes or so, one of the OCR processes dissappears, and only 2 remain alive at any given time. When there are 10 JMS messages or so remaining, another OCR process stops, and there is only 1 at any given time.

最后,所有50个文档都被OCRed ,并且任何OCR进程或我的应用程序都不会抛出任何异常。

In the end, all 50 documents have been OCRed, and no exception is being thrown by any of the OCR processes or my application.

我发现这种行为很奇怪,因为我希望在任何时间消耗JMS消息时都会有3个OCR进程处于活动状态(当然除外)。如果在队列中输入时将JMS消息分配到MDB实例,而不是实时,则可以解释此行为。例如,如果为每个MDB分配了大约17条消息。根据文档大小,当其他MDB实例仍然可以使用消息时,某些MDB实例可以提前完成并保持空闲而不消耗任何其他消息。

I find this behaviour strange because I would expect that there would be 3 OCR processes alive at any point in time consuming JMS messages (except at the end of course). This behaviour could be explained if the JMS messages are "assigned" to the MDB instances upon entry in the Queue, and not real time. For instance, if each MDB was assigned around 17 messages. Depending on the document sizes, some MDB instances could finish earlier and stay idle without consuming any other messages, when the other MDB instances could still have messages to consume.

这是怎么了?如果是,是否有办法更改此设置,以便每当MDB实例完成处理消息时都会发生消息到MDB实例的分配?

Is this what is happening? If yes, is there a way to change this so that the assignment of messages to MDB instances happens whenever an MDB instance finishes processing a message?

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "queue/csrOcrQueue"),
        @ActivationConfigProperty(propertyName = "minSession", propertyValue = "3"),
        @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "3")
})
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class OcrMessageListener implements MessageListener {


推荐答案

这与客户端(MDB)上的JMS消息缓冲有关。默认情况下,将启用消息缓冲以避免网络延迟。但是,对于我的客户速度慢的情况,这不是问题。

This has to do with JMS message buffering on the client (MDB). Message buffering is by default turned on to avoid network latency. However, for my case where I have slow clients, this is't a problem.

这是来自 HornetQ文档


11.1.39。没有消费者缓冲

默认情况下,HornetQ消费者会在
客户端缓冲区中缓冲来自服务器的消息,然后才能在客户端$上实际收到消息b $ b方。这提高了性能,因为否则每次调用
receive()或处理MessageListener
onMessage()方法中的最后一条消息时,HornetQ客户端都必须将服务器转到
请求下一条消息,然后将被发送到客户端
方(如果有的话)。

By default, HornetQ consumers buffer messages from the server in a client side buffer before you actually receive them on the client side. This improves performance since otherwise every time you called receive() or had processed the last message in a MessageListener onMessage() method, the HornetQ client would have to go the server to request the next message, which would then get sent to the client side, if one was available.

这将涉及每条消息的网络往返并减少
表现。因此,默认情况下,HornetQ会将消息预取到每个消费者的
a缓冲区。

This would involve a network round trip for every message and reduce performance. Therefore, by default, HornetQ pre-fetches messages into a buffer on each consumer.

在某些情况下,缓冲是不可取的,HornetQ允许它为
关闭。此示例演示了。

In some case buffering is not desirable, and HornetQ allows it to be switched off. This example demonstrates that.

Github中有一个示例项目作为文档的一部分,其中关闭了消费者缓冲:链接

There is a sample project in Github as part of the documentation, where consumer buffering is turned off: link

这篇关于Wildfly JMS:当消息存在时,MDB bean空闲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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