tags:

views:

218

answers:

4

In a Java web application I have a recurring message load of type A (e.g., 20,000 every hour). Then I have a second type of messages (type B) that show up occasionally but have a higher priority than type A (say, 3,000). I want to be able to process these messages on one or more machines using open source software.

It seems to me that I could do that with JMS if I had a JMS server that would send messages from its queue based on priorities (e.g., send three message of type B and then one of type A even though all messages of type A are at the top of the message queue).

Do you know a JMS server that can do that - or do you know another way to implement this?

+4  A: 

The JMS standard supports message priorities default is 4, you can specify others). I think you need to set that in the message producer AND in the message itself (there are methods on both).

I think that ActiveMQ does support it.

However, many JMS broker have priority handling disabled by default. There is a flag that you may need to change, something like "supportJMSPriority", somewhere in the broker configuration.

Also, Apache Camel lets you write your own message resequencers so you could implement any form of priority that you would like.

Uri
+1  A: 

Set the message priority when you call "send(..)" on the MessageProducer (QueueSender, etc). Or, you can set the default priority on the MessageProducer from 0-9 (9 is highest). Setting the priority on the message itself won't work. It's overridden by the Producer.

Uri is correct--whether or not the priority is respected is implementation specific. I believe OpenJMS generally respects the priority out-of-the-box, but does not guarantee it.

JMS Spec states: "JMS does not require that a provider strictly implement priority ordering of messages; however, it should do its best to deliver expedited messages ahead of normal messages."

James Schek
A: 

Why not consider using another MDB to process the other message type explicitly. The priority details above still apply, further more you would have more control over concurrent processing for each message type.

For most situations i prefer 1 mdb or message receiver per message type. This way if a transaction rolls back you know immediately which type of message caused the problem

Karl

Karl
A: 

You could use more than one topic. Even with priorities, if your processor is tied up processing a lower priority message it won't stop what its doing.

If you have separate processors, a high priority message can start processing as soon as it can be delivered, not waiting for any other message to be processed.

Peter Lawrey