IBM Support

Difference between message.setJMSDeliveryMode and producer.setDeliveryMode (JMS)

Question & Answer


You want to know the difference between the WebSphere MQ JMS methods: message.setJMSDeliveryMode and producer.setDeliveryMode


a) By default, the delivery mode from a JMS Producer is to set the attribute PERSISTENT for messages.

b) If you want to specify Non-Persistent messages from a JMS Producer, you will need to use "setDeliveryMode" as follows:

import javax.jms.DeliveryMode;

c) The JMS message.setJMSDeliveryMode is ONLY applicable when receiving messages.
This method is IGNORED when sending messages.

+++ References Class MQMessageProducer
      Sets the producer's default delivery mode.
      deliveryMode - the message delivery mode for this message producer. Possible values are:
      DeliveryMode.PERSISTENT, the default
    See Also:
    getDeliveryMode(), Message.DEFAULT_DELIVERY_MODE

javax.jms Interface Message
    public static final int DEFAULT_DELIVERY_MODE
    The message producer's default delivery mode is PERSISTENT. Class JMSTextMessage
    Sets the delivery mode for this message.
    Any value set using this method is ignored when the message is sent, but this method can be used to change the value in a received message.
    To alter the delivery mode when a message is sent, use the setDeliveryMode() method on the QueueSender or TopicPublisher (this method is inherited from MessageProducer).
    Specified by:
    setJMSDeliveryMode in interface Message
    deliveryMode - the delivery mode for this message

[{"Product":{"code":"SSFKSJ","label":"WebSphere MQ"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Java","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.0;8.0;7.5;7.1;7.0;6.0","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}}]

Document Information

Modified date:
15 June 2018