views:

36

answers:

2

Hi, 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

+1  A: 

A classic case of message handling in clustered environment. This is what I would do.

Use Broadcast message (Channel based) in place of Queue. Queue being useful for point to point communication is not very effective. Set validity of message till the time it is consumed by one of the consumer. This way, other consumers wont even see the message and only one consumer will consume it.

Tushar Tarkas
Hi Tushar, thanks for your help.What is `Broadcast message`? Is it a different kind of message which is sent on a JMS queue? Also what did you mean by: "Queue being useful for point to point communication is not very effective"?Thanks
Ittai
I meant used a topic based communication in place of queue based communication where you will have to specify a destination while passing the message or will have to implement some kind of router logic to route it the message to a specific consumer based on certain criteria.
Tushar Tarkas
Hi Tushar, I read a bit about Topic vs. Queue and your solutions sounds excellent.The only thing I did not understand is regarding the "Set validitiy of message..." Why do I need to set its validity? Won't it be consumed by one consumer by definition of the Topic mechanism?Ittai
Ittai
A: 

Take a look at JGroups. You may consider implementing your module/subscribers to use jgroups for the kind of synchronization you need. JGroups provide Reliable Multicast Communication.

Gopi