Handling Priority Messages

In a Java web application, I have a repeated download of a Type A message (e.g. 20,000 every hour). Then I have a second type of message (type B) that appear occasionally but have a higher priority than type A (say 3000). 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 this using JMS if I had a JMS server that sent messages from its queue based on priorities (for example, sent three messages of type B, and then one of types A, although all messages type A is at the top of the message queue).

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

+6
java message-queue
source share
4 answers

Set the priority of the message when you call "send (..)" in MessageProducer (QueueSender, etc.). Or you can set the default priority for MessageProducer from 0-9 (maximum 9). Priority setting in the message itself will not work. He is redefined by the Producer.

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

JMS Spec: "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."

+2
source share

The JMS standard supports message priority by default - 4, you can specify others). I think you need to set this in the AND message editor in the message itself (both have methods).

I think ActiveMQ supports it.

However, many JMS brokers disable priority processing by default. There is a flag that you may need to change, for example, "supportJMSPriority", somewhere in the broker's configuration.

In addition, Apache Camel allows you to write your own message requisites so that you can implement any form of priority that you would like.

+6
source share

Why not use a different MDB to handle a different type of message explicitly. The above priorities still apply, and even more you will have more control over concurrent processing for each type of message.

In most cases, I prefer 1 mdb or message receiver per message type. That way, if the transaction is rolled back, you immediately know what type of message caused the problem.

Charles

0
source share

You can use more than one topic. Even with priorities, if your processor is attached to processing a message with a lower priority, it will not stop what it is doing.

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

0
source share

All Articles