Skip to content

Commit f67f861

Browse files
committed
jms-priority
1 parent 1cf4cda commit f67f861

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

modules/examples/pages/pulsar-jms-implementation.adoc

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ A discussion of design and implementation decisions made to support JMS requirem
1414
* xref:pulsar-jms-implementation.adoc#message-selectors[Message selectors and `noLocal` subscriptions]
1515
* xref:pulsar-jms-implementation.adoc#schema-registry[]
1616
* xref:pulsar-jms-implementation.adoc#subscription-creation[Subscription creation]
17-
* xref:pulsar-jms-implementation.adoc#system-properties[System properties and fields]
17+
* xref:pulsar-jms-implementation.adoc#system-properites[System properties and fields]
1818
* xref:pulsar-jms-implementation.adoc#temporary-destinations[]
1919
* xref:pulsar-jms-implementation.adoc#transaction-emulation[]
2020
* xref:pulsar-jms-implementation.adoc#unsupported-features[Unsupported and emulated features]
2121
* xref:pulsar-jms-implementation.adoc#auth-on-creation[Username and password authentication]
22-
* xref:pulsar-jms-implementation.adoc#schema-registry[Using the Pulsar Schema Registry]
22+
* xref:pulsar-jms-implementation.adoc#jms-priority[]
2323
* xref:pulsar-jms-implementation.adoc#virtual-destinations[]
2424
2525
[#client-id]
@@ -399,6 +399,46 @@ try (PulsarConnectionFactory factory = new PulsarConnectionFactory(properties);
399399

400400
For more on multi-topic subscriptions in Pulsar, see the https://pulsar.apache.org/docs/client-libraries-java/#multi-topic-subscriptions[Pulsar documentation].
401401

402+
[#jms-priority]
403+
== JMS priority
404+
405+
*JMS priority* allows messages to be dispatched at different rates according to priority. +
406+
Priorities are <<Mapping JMS priority to partitions,mapped to Pulsar partition IDs>> with the `jms.priorityMapping` parameter in the ConnectionFactory. +
407+
408+
When a producer writes a message, the message is routed to a partition based on its priority mapping. By default, the higher the partition name (0 is highest priority), the higher the priority. +
409+
On the consumer side, messages are re-ordered in memory so high priority partitions are drained faster than other partitions. +
410+
Both producers and consumers advertise their priority routing behavior in metadata, so priority behavior can be detected and used by Pulsar admin for subscriptions, filters, and metrics. +
411+
Even if a consumer is not looking for a message's priority mapping metadata, it will still consume the message.
412+
413+
[#jms-priority-mapping]
414+
=== Mapping JMS priority to partitions
415+
416+
The parameter `jms.priorityMapping` controls how priorities are mapped to partitions.
417+
418+
The `jms.priorityMapping` parameter can be set to `linear` or `non-linear`. The default is `linear`. +
419+
420+
In `jms.priorityMapping = "linear"` mode, the priority level (from 0 to 9) is linearly mapped to the partition id. +
421+
If you have 10 partitions, priority 0 goes to partition 0, priority 1 to partition 1, and so on. +
422+
If you have 20 partitions, priority 0 goes to partitions 0 and 1, priority 1 goes to partitions 2 and 3, and so on.
423+
424+
The benefit of this approach is that you are guaranteed that each priority level is sent to different partitions. +
425+
The drawback is that if you don't use all the priority levels, then some partitions will be left underutilized.
426+
427+
In `jms.priorityMapping = "non-linear"`, the mapping between JMSPriority and the partition id is not linear.
428+
The assumption is that there will be more regular messages than high/low priority messages.
429+
430+
Priorities are divided into 3 classes: low, default, and high priority.
431+
432+
* 1/4 of the partitions are for low priority messages.
433+
* 1/2 of the partitions are for the default priority.
434+
* 1/4 of the partitions are for high priority messages.
435+
436+
With non-linear partition mapping, the JMS Client will tend to:
437+
438+
* use more partitions for default level priorities (especially 4, the default priority).
439+
* map higher level priorities to higher partition ids.
440+
* map lower level priorities to lower partition ids.
441+
402442
== What's next?
403443

404444
* *xref:jms-migration:pulsar-jms-quickstart-sa.adoc[]*: Create a simple command line Java JMS client that connects to a local Pulsar installation.

0 commit comments

Comments
 (0)