具有多个使用者的JMS队列

编程入门 行业动态 更新时间:2024-10-25 00:29:08
本文介绍了具有多个使用者的JMS队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带HornetQ的JBoss-6服务器和一个队列:

I have a JBoss-6 server with HornetQ and a single queue:

<queue name="my.queue"> <entry name="/queue/test"/> </queue>

有一个不同的消费者(在不同的机器上)连接到这个队列,但只有一个单个消费者一次是活跃的。如果我关闭此消费者,消息会立即由其他消费者处理。

There a different consumers (on different machines) connected to this queue, but only a single consumer is active at a time. If I shut down this consumer, the messages are immediately processed by one of the other consumers.

由于我的消息有一些耗时的处理,我希望多个消费者处理他们独特的消息同时发生。

Since my messages have some time consuming processing, I want multiple consumer process their unique messages concurrently.

我记得在早期版本的JBoss中有类似的情况,这种设置没有问题。在Jboss-6中,消息传递系统运行良好 - 除了上述问题。这个问题类似于在hornetq中可能有多个客户端消费者吗?,但这种情况与我的情况不同。

I remember a similar in earlier versions of JBoss where this setup worked without problems. Here in Jboss-6 the messaging system is working well -- except of the issue described above. This question is similar to Are multiple client consumers possible in hornetq?, but the scenario is not similar to mine.

更新1 :如果我关闭(STRG + C)一个消费者,则会有一个短暂的超时(直到服务器识别出丢失的消费者),直到下一个消费者获得消息。

Update 1: If I close (STRG+C) one consumer there is a short timeout (until the server recognized the lost consumer) until the next consumer gets the message.

更新2 :代码段

VoidListener ml = new VoidListener(); QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("ConnectionFactory"); QueueConnection conn = qcf.createQueueConnection(); Queue queue = (Queue) ctx.lookup(queueName); QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); QueueReceiver recv = session.createReceiver(queue,""); recv.setMessageListener(ml); conn.start();

和MessageListerner:

And the MessageListerner:

public class OlVoidListener implements MessageListener { public void onMessage(Message msg) { counter++; logger.debug("Message ("+counter+") received"); try {Thread.sleep(15*1000);} catch (InterruptedException e) {} } }

推荐答案

队列中有多个消费者,消费者之间的消息负载均衡。

With multiple consumers on a queue, messages are load balanced between the consumers.

由于你有时间消息,你应该通过设置消费者窗口大小来禁用缓冲。

As you have some time consuming the message, you should disable buffering by setting consumer-window-size.

在hornetQ上有一个关于分发的例子,关于如何禁用客户端缓冲并为慢速消费者提供更好的支持。 (一个缓慢的消费者是一个消费者,它将有一些时间处理消息)

On hornetQ there's an example on the distribution, about how to disable client buffering and give a better support for slow consumers. (a slow consumer is a consumer that will have some time processing the message)

消息系统将预取/预读消息到客户端缓冲区以加速处理并避免网络延迟。如果您有快速处理队列和单个消费者,这不是问题。

message systems will pre-fetch/read-ahead messages to the client buffer to speed up processing and avoid network latency. This is not an issue if you have fast processing queues and a single consumer.

JBoss Messaging在连接工厂提供了慢消费者选项,而hornetq提供了消费者窗口大小。

JBoss Messaging offered the slow-consumer option at the connection factory and hornetq offers the consumer window size.

大多数消息系统将为您提供启用或禁用客户端预取的方法。

Most Message systems will provide you a way to enable or disable client pre-fetching.

更多推荐

具有多个使用者的JMS队列

本文发布于:2023-10-15 00:55:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   队列   使用者   JMS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!