2

I have a module which runs standalone in a JVM (no containers) and communicates with other modules via JMS. My module is both a producer in one queue and a consumer in a different queue. I have then need to cluster this module, both for HA reasons and for workload reasons, and I'm probably going to go with Terracotta+Hibernate for clustering my entities. Currently when my app starts it launches a thread (via Executors.newSingleThreadExecutor()) which serves as the consumer (I can attach actual code sample if relevant and neccessary).

What I understood from reading questions here is that if I just start up my module on N different JVMs then N different subscribers will be created and each message in the queue will arrive to N subscribers. What I'd like to do is have only one of them (let's currently say that which one is not important) process that message and so in actuality enable me to process N messages at a time.

How can/should this be done? Am I way off the track?

BTW, I'm using OpenMQ as my implementation but I don't know if that's relevant.

Thanks for any help

4

2 回答 2

1

集群环境中消息处理的经典案例。这就是我会做的。

使用广播消息(基于频道)代替队列。队列对于点对点通信很有用并不是很有效。设置消息的有效性,直到它被消费者之一消费。这样,其他消费者甚至不会看到消息,只有一个消费者会消费它。

于 2010-08-17T10:21:44.863 回答
0

看看JGroups。您可以考虑实现您的模块/订阅者以使用 jgroups 进行您需要的同步。JGroups 提供可靠的多播通信。

于 2010-08-17T10:52:24.383 回答