Class ActiveMQMessageProducerSupport

java.lang.Object
org.apache.activemq.ActiveMQMessageProducerSupport
All Implemented Interfaces:
jakarta.jms.MessageProducer, AutoCloseable, Closeable
Direct Known Subclasses:
ActiveMQMessageProducer

public abstract class ActiveMQMessageProducerSupport extends Object implements jakarta.jms.MessageProducer, Closeable
A useful base class for implementing a MessageProducer
  • Field Details

    • session

      protected ActiveMQSession session
    • disableMessageID

      protected boolean disableMessageID
    • disableMessageTimestamp

      protected boolean disableMessageTimestamp
    • defaultDeliveryMode

      protected int defaultDeliveryMode
    • defaultPriority

      protected int defaultPriority
    • defaultTimeToLive

      protected long defaultTimeToLive
    • sendTimeout

      protected int sendTimeout
    • JMS_PROPERTY_NAMES_DISALLOWED

      public static final Set<String> JMS_PROPERTY_NAMES_DISALLOWED
  • Constructor Details

    • ActiveMQMessageProducerSupport

      public ActiveMQMessageProducerSupport(ActiveMQSession session)
  • Method Details

    • setDeliveryDelay

      public void setDeliveryDelay(long deliveryDelay) throws jakarta.jms.JMSException
      Gets the delivery delay associated with this MessageProducer.
      Specified by:
      setDeliveryDelay in interface jakarta.jms.MessageProducer
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to close the producer due to some internal error.
      Since:
      2.0
    • getDeliveryDelay

      public long getDeliveryDelay() throws jakarta.jms.JMSException
      Gets the delivery delay value for this MessageProducer.
      Specified by:
      getDeliveryDelay in interface jakarta.jms.MessageProducer
      Returns:
      the delivery delay for this messageProducer
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to determine if deliver delay is disabled due to some internal error.
    • setDisableMessageID

      public void setDisableMessageID(boolean disableMessageID) throws jakarta.jms.JMSException
      Sets whether message IDs are disabled.

      Since message IDs take some effort to create and increase a message's size, some JMS providers may be able to optimize message overhead if they are given a hint that the message ID is not used by an application. By calling the setDisableMessageID method on this message producer, a JMS client enables this potential optimization for all messages sent by this message producer. If the JMS provider accepts this hint, these messages must have the message ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.

      Message IDs are enabled by default.

      Specified by:
      setDisableMessageID in interface jakarta.jms.MessageProducer
      Parameters:
      disableMessageID - indicates if message IDs are disabled
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to close the producer due to some internal error.
    • getDisableMessageID

      public boolean getDisableMessageID() throws jakarta.jms.JMSException
      Gets an indication of whether message IDs are disabled.
      Specified by:
      getDisableMessageID in interface jakarta.jms.MessageProducer
      Returns:
      an indication of whether message IDs are disabled
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to determine if message IDs are disabled due to some internal error.
    • setDisableMessageTimestamp

      public void setDisableMessageTimestamp(boolean disableMessageTimestamp) throws jakarta.jms.JMSException
      Sets whether message timestamps are disabled.

      Since timestamps take some effort to create and increase a message's size, some JMS providers may be able to optimize message overhead if they are given a hint that the timestamp is not used by an application. By calling the setDisableMessageTimestamp method on this message producer, a JMS client enables this potential optimization for all messages sent by this message producer. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint, the timestamp must be set to its normal value.

      Message timestamps are enabled by default.

      Specified by:
      setDisableMessageTimestamp in interface jakarta.jms.MessageProducer
      Parameters:
      disableMessageTimestamp - indicates if message timestamps are disabled
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to close the producer due to some internal error.
    • getDisableMessageTimestamp

      public boolean getDisableMessageTimestamp() throws jakarta.jms.JMSException
      Gets an indication of whether message timestamps are disabled.
      Specified by:
      getDisableMessageTimestamp in interface jakarta.jms.MessageProducer
      Returns:
      an indication of whether message timestamps are disabled
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to close the producer due to some internal error.
    • setDeliveryMode

      public void setDeliveryMode(int newDeliveryMode) throws jakarta.jms.JMSException
      Sets the producer's default delivery mode.

      Delivery mode is set to PERSISTENT by default.

      Specified by:
      setDeliveryMode in interface jakarta.jms.MessageProducer
      Parameters:
      newDeliveryMode - the message delivery mode for this message producer; legal values are DeliveryMode.NON_PERSISTENT and DeliveryMode.PERSISTENT
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to set the delivery mode due to some internal error.
      See Also:
      • MessageProducer.getDeliveryMode()
      • DeliveryMode.NON_PERSISTENT
      • DeliveryMode.PERSISTENT
      • Message.DEFAULT_DELIVERY_MODE
    • getDeliveryMode

      public int getDeliveryMode() throws jakarta.jms.JMSException
      Gets the producer's default delivery mode.
      Specified by:
      getDeliveryMode in interface jakarta.jms.MessageProducer
      Returns:
      the message delivery mode for this message producer
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to close the producer due to some internal error.
    • setPriority

      public void setPriority(int newDefaultPriority) throws jakarta.jms.JMSException
      Sets the producer's default priority.

      The JMS API defines ten levels of priority value, with 0 as the lowest priority and 9 as the highest. Clients should consider priorities 0-4 as gradations of normal priority and priorities 5-9 as gradations of expedited priority. Priority is set to 4 by default.

      Specified by:
      setPriority in interface jakarta.jms.MessageProducer
      Parameters:
      newDefaultPriority - the message priority for this message producer; must be a value between 0 and 9
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to set the delivery mode due to some internal error.
      See Also:
      • MessageProducer.getPriority()
      • Message.DEFAULT_PRIORITY
    • getPriority

      public int getPriority() throws jakarta.jms.JMSException
      Gets the producer's default priority.
      Specified by:
      getPriority in interface jakarta.jms.MessageProducer
      Returns:
      the message priority for this message producer
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to close the producer due to some internal error.
      See Also:
      • MessageProducer.setPriority(int)
    • setTimeToLive

      public void setTimeToLive(long timeToLive) throws jakarta.jms.JMSException
      Sets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.

      Time to live is set to zero by default.

      Specified by:
      setTimeToLive in interface jakarta.jms.MessageProducer
      Parameters:
      timeToLive - the message time to live in milliseconds; zero is unlimited
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to set the time to live due to some internal error.
      See Also:
      • MessageProducer.getTimeToLive()
      • Message.DEFAULT_TIME_TO_LIVE
    • getTimeToLive

      public long getTimeToLive() throws jakarta.jms.JMSException
      Gets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.
      Specified by:
      getTimeToLive in interface jakarta.jms.MessageProducer
      Returns:
      the message time to live in milliseconds; zero is unlimited
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to get the time to live due to some internal error.
      See Also:
      • MessageProducer.setTimeToLive(long)
    • send

      public void send(jakarta.jms.Message message) throws jakarta.jms.JMSException
      Sends a message using the MessageProducer's default delivery mode, priority, and time to live.
      Specified by:
      send in interface jakarta.jms.MessageProducer
      Parameters:
      message - the message to send
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to send the message due to some internal error.
      jakarta.jms.MessageFormatException - if an invalid message is specified.
      jakarta.jms.InvalidDestinationException - if a client uses this method with a MessageProducer with an invalid destination.
      UnsupportedOperationException - if a client uses this method with a MessageProducer that did not specify a destination at creation time.
      Since:
      1.1
      See Also:
      • Session.createProducer(jakarta.jms.Destination)
      • MessageProducer
    • send

      public void send(jakarta.jms.Message message, int deliveryMode, int priority, long timeToLive) throws jakarta.jms.JMSException
      Sends a message to the destination, specifying delivery mode, priority, and time to live.
      Specified by:
      send in interface jakarta.jms.MessageProducer
      Parameters:
      message - the message to send
      deliveryMode - the delivery mode to use
      priority - the priority for this message
      timeToLive - the message's lifetime (in milliseconds)
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to send the message due to some internal error.
      jakarta.jms.MessageFormatException - if an invalid message is specified.
      jakarta.jms.InvalidDestinationException - if a client uses this method with a MessageProducer with an invalid destination.
      UnsupportedOperationException - if a client uses this method with a MessageProducer that did not specify a destination at creation time.
      Since:
      1.1
      See Also:
      • Session.createProducer(jakarta.jms.Destination)
    • send

      public void send(jakarta.jms.Destination destination, jakarta.jms.Message message) throws jakarta.jms.JMSException
      Sends a message to a destination for an unidentified message producer. Uses the MessageProducer's default delivery mode, priority, and time to live.

      Typically, a message producer is assigned a destination at creation time; however, the JMS API also supports unidentified message producers, which require that the destination be supplied every time a message is sent.

      Specified by:
      send in interface jakarta.jms.MessageProducer
      Parameters:
      destination - the destination to send this message to
      message - the message to send
      Throws:
      jakarta.jms.JMSException - if the JMS provider fails to send the message due to some internal error.
      jakarta.jms.MessageFormatException - if an invalid message is specified.
      jakarta.jms.InvalidDestinationException - if a client uses this method with an invalid destination.
      UnsupportedOperationException - if a client uses this method with a MessageProducer that specified a destination at creation time.
      See Also:
      • Session.createProducer(jakarta.jms.Destination)
      • MessageProducer
    • checkClosed

      protected abstract void checkClosed() throws jakarta.jms.IllegalStateException
      Throws:
      jakarta.jms.IllegalStateException
    • getSendTimeout

      public int getSendTimeout()
      Returns:
      the sendTimeout
    • setSendTimeout

      public void setSendTimeout(int sendTimeout)
      Parameters:
      sendTimeout - the sendTimeout to set
    • validateValidPropertyName

      public static void validateValidPropertyName(String propertyName) throws jakarta.jms.IllegalStateRuntimeException
      Throws:
      jakarta.jms.IllegalStateRuntimeException
    • validateValidPropertyValue

      public static void validateValidPropertyValue(String propertyName, Object propertyValue) throws jakarta.jms.IllegalStateRuntimeException
      Throws:
      jakarta.jms.IllegalStateRuntimeException