具有多个使用者的JMS队列 [英] JMS queue with multiple consumers

查看:105
本文介绍了具有多个使用者的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队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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