Question

I am learning JMS and came across this statement: http://docs.oracle.com/javaee/1.3/jms/tutorial/1_3_1-fcs/doc/advanced.html#1023387

The PERSISTENT delivery mode, the default, instructs the JMS provider to take extra care to ensure that a message is not lost in transit in case of a JMS provider failure. A message sent with this delivery mode is logged to stable storage when it is sent.

If JMS Provider failure occurs then how the JMS Provider can ensure that a message is not lost?

What does it mean that:

"A message sent with this delivery mode is logged to stable storage when it is sent."

Please help me in understanding the JMS concept here.

Was it helpful?

Solution

It means the message with PERSISTENT delivery mode is not lost when a messaging provider goes down for any reason and comes up again. The messaging provider saves messages with PERSISTENT delivery mode to disk and when the message provides restarts, the message is read from the disk and brought into memory.

Hope this is clear.

OTHER TIPS

You can do a simple test to understand the concept. Refer the tutorial here on how to create producer and consumer.

You will see producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); Change it to producer.setDeliveryMode(DeliveryMode.PERSISTENT);

Now create two classes. One which calls only Producers and one only consumer.

public class AppOnlyProduce { public static void thread(Runnable runnable, boolean daemon) { Thread brokerThread = new Thread(runnable); brokerThread.setDaemon(daemon); brokerThread.start(); } public static void main(String[] args) throws InterruptedException { thread(new HelloWorldProducer(), false); thread(new HelloWorldProducer(), false); } }

public class AppOnlyConsumer { public static void thread(Runnable runnable, boolean daemon) { Thread brokerThread = new Thread(runnable); brokerThread.setDaemon(daemon); brokerThread.start(); } public static void main(String[] args) throws InterruptedException { thread(new HelloWorldConsumer(), false); thread(new HelloWorldConsumer(), false); } } First run AppOnlyProduce. It will create two messages. Now run AppOnlyConsumer it will read two messages. Now change back the line to producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

Again run AppOnlyProduce. It will create two messages. Now run AppOnlyConsumer You will see that it waits for sometime for message and they say Received: null

In first case mode was persistent. So though Java program ended messages were persisted and made available when JMS started (this time by consumer)

In second case mode was not persistent. So messages vanished as soon as program ended.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top