hornetq中可能有多个客户消费者吗?

hornetq中可能有多个客户消费者吗?

问题描述:

在我的客户端应用程序中,我创建了多个使用者,但是它们不能同时处理队列.通常,只有一个使用者处理队列消息.我不知道为什么.

In my client application, I create several consumers, but they can't concurrently process the queue. Always, only a single consumer processes the queue messages. I don't know why.

Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
env.put(Context.PROVIDER_URL, "192.168.1.111:1099");
InitialContext ctx = new InitialContext(env);

ConnectionFactory cf = (ConnectionFactory) ctx.lookup("/ConnectionFactory");
Queue downQueue = (Queue) ctx.lookup("queue/DownQueue");
Session consumerSession = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer consumer;
for (int i = 0; i < 2; i++) {
    consumer = consumerSession.createConsumer(downQueue, "proxyId=0");
    consumer.setMessageListener(listener);
}

如何处理具有多个并发使用者的队列?

How do I process the queue with multiple concurrent consumers?

在线程和会话之间将其视为1比1. (连接是线程安全的,下面"的所有内容都不是).简而言之,创建多个线程,让每个线程创建一个会话等.每个线程都会消耗.

Think of it as 1 to 1 between threads and sessions. (Connections are thread safe, everything "below" is not). So in short, create multiple threads, have each thread create a session etc. And each thread will consume.