Skip to Main Content
Java Message Service
book

Java Message Service

by David A Chappell, Richard Monson-Haefel
December 2000
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 9m
English
O'Reilly Media, Inc.
Content preview from Java Message Service

Name

JMSPriority — Purpose: Routing

Synopsis

Messages may be assigned a priority by the message producer when they are delivered. The message servers may use message’s priority to order delivery of messages to consumers; messages with a higher priority are delivered ahead of lower priority messages.

The message’s priority is contained in the JMSPriority header, which is set automatically by the JMS provider. The priority of messages can be declared by the JMS client using the setPriority( ) method on the producer. The following code shows how this method is used by both the p2p and pub/sub message models:

// p2p setting the message priority to 9
QueueSender queueSender = QueueSession.createSender(someQueue);
queueSender.setPriority(9);

//pub/sub setting the message priority to 9
TopicPublisher topicPublisher = TopicSession.createPublisher(someTopic);
topicPublisher.setPriority(9);

Once a priority is established on a producer (QueueSender or TopicPublisher), that priority will be used for all messages delivered from that producer, unless it is explicitly overridden. The priority of a specific message can be overridden during the send operation. The following code shows how to override the priority of a message during the send operation. In both cases, the priority is set to 3:

// p2p setting the priority on the send operation
QueueSender queueSender = QueueSession.createSender(someQueue);

queueSender.send(message,DeliveryMode.PERSISTENT, 3, 0); // pub/sub setting the priority on the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Spring Boot 2.0

Mastering Spring Boot 2.0

Dinesh Rajput
Cloud Native Java

Cloud Native Java

Josh Long, Kenny Bastani

Publisher Resources

ISBN: 0596000685Supplemental ContentErrata Page