concept nonpersistent message in category activemq

appears as: nonpersistent messages, nonpersistent message
ActiveMQ in Action

This is an excerpt from Manning's book ActiveMQ in Action.

  • Uses nonpersistent messages
  • You can do two simple things to improve JMS messaging performance: use nonpersistent messaging, or if you really need guaranteed messaging, then use transactions to batch up large groups of messages. Usually nonpersistent message delivery isn’t a consideration unless you don’t care that a message will be lost (for example, in real-time data feeds, since the status will be sent repeatedly within such a short period of time), and batching messages in transactions won’t always be applicable. But ActiveMQ incorporates failsafes for reliable delivery of nonpersistent messages so that only catastrophic failure would result in message loss. In this section we’ll explain why nonpersistent message delivery and batching messages are faster, and why they could be applicable to use in your application if you don’t need to absolutely guarantee that messages will never be lost.

    As by default the message delivery mode is persistent, you have to explicitly set the delivery mode on the MessageProducer to send nonpersistent messages as can be seen in the following listing.

    Listing 13.1. Persistent message delivery
    MessageProducer producer = session.createProducer(topic); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    We’ve seen why there’s such a big performance difference between persistent and nonpersistent delivery of messages, and the steps that ActiveMQ takes to improve reliability of nonpersistent messages. The benefit of reliable message delivery allows nonpersistent messages to be used in many more cases than would be typical of a JMS provider.

    Having covered nonpersistent messages, let’s move on to the second generalized technique for improving performance of delivering messages in your application—batching messages together. The easiest way to batch messages is to use transaction boundaries, which are explained next.