Consultor Eletrônico



Kbase 19699: SonicMQ: JMSPriority - Everything You Need to Know
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/17/2004
SUMMARY:

This solution applies to Progress SonicMQ Version 2000.x and 3.x.

The Java Message Service (JMS) message header field JMSPriority may be
used to move a message ahead of other undelivered messages sent to a
Topic or Queue, as well as to allow message selectors to pick messages
having a given priority.


EXPLANATION:

Many users expect all messages with a higher priority to be delivered
before those with a lower priority value. However, the JMS
specification does not require a provider to implement the priority
ordering of messages, although the SonicMQ broker does its best to
deliver messages having a higher priority ahead of messages with
lower values.

Priority is only a suggestion to the JMS provider, and can only order
delivery of undelivered messages; messages having lower priority may
already have been consumed by the time a message with higher priority
arrives on the broker/server; when a client is actively consuming
messages, the cache of undelivered messages from which the server
selects the next message to send is constantly changing. Therefore,
although messages of the same priority from a single producer are
always received in the order in which they were sent, it is impossible
to specify the exact the order in which messages will be received by a
message consumer when a message producer sends messages of different
priorities. The best way to see the effect of message priority on
message delivery is with a Queue or a durable subscription with no
active consumer.

JMS defines ten levels of message priority with values 0 through 9,
where 0 is the lowest and 9 is the highest. Zero through four are
considered 'normal' settings and five through nine, 'expedited.'


SOLUTION:

A common misconception is that a JMS client can use the method

(Message m).setJMSPriority(int priority)

to set the priority of a message.

However, an attempt by a JMS client to change the message priority
with this method has no effect on message priority. This method is
used by the JMS provider (SonicMQ broker ) to set a message's
JMSpriority header field.

The priority of a given message is determined by the priority assigned
to the message when it is sent to its destination (Topic or Queue), if
specified, and otherwise, by the default priority of the
MessageProducer.

To set the priority for an individual message in the Publish/Subscribe
domain, use the following method:

TopicPublisher.publish(Message message,
int deliveryMode,
int priority,
int timeToLive)

To set the priority for an individual message in the Point to Point
domain when sending the message from a QueueSender bound to a
particular queue, use this method:

QueueSender.send(Message message,
int deliveryMode,
int priority,
int timeToLive)

To set the priority for an individual message in the Point to Point
domain when sending the message from an unbound QueueSender, use this
method:

QueueSender.send(Queue queue
Message message,
int deliveryMode,
int priority,
int timeToLive)

The default priority for a MessageProducer is set with the method:

MessageProducer.setPriority (int priority)

References to Written Documentation:

SonicMQ 2000.x Programming Guide, Chapter 7, "Messages".

SonicMQ 3.x Programming Guide, Chapter 4, "Messages".

SonicMQ API Reference.