Class RMQMessage

  • All Implemented Interfaces:
    jakarta.jms.Message, java.lang.Cloneable
    Direct Known Subclasses:
    RMQBytesMessage, RMQMapMessage, RMQObjectMessage, RMQStreamMessage, RMQTextMessage

    public abstract class RMQMessage
    extends java.lang.Object
    implements jakarta.jms.Message, java.lang.Cloneable
    Base class for RMQ*Message classes. This is abstract and cannot be instantiated independently.
    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
        Logger shared with derived classes
      • NOT_READABLE

        protected static final java.lang.String NOT_READABLE
        Error message when the message is not readable
        See Also:
        Constant Field Values
      • NOT_WRITEABLE

        protected static final java.lang.String NOT_WRITEABLE
        Error message when the message is not writeable
        See Also:
        Constant Field Values
      • UNABLE_TO_CAST

        protected static final java.lang.String UNABLE_TO_CAST
        Error message used when throwing MessageFormatException
        See Also:
        Constant Field Values
      • MSG_EOF

        protected static final java.lang.String MSG_EOF
        Error message when we get an EOF exception
        See Also:
        Constant Field Values
      • DEFAULT_MESSAGE_BODY_SIZE

        protected static final int DEFAULT_MESSAGE_BODY_SIZE
        When we create a message that has a byte[] as the underlying structure, BytesMessage and StreamMessage, this is the default size. Can be changed with a system property.
    • Constructor Detail

      • RMQMessage

        public RMQMessage()
        Constructor for auto de-serialization
    • Method Detail

      • loggerDebugByteArray

        protected void loggerDebugByteArray​(java.lang.String format,
                                            byte[] buffer,
                                            java.lang.Object arg)
      • isReadonlyBody

        protected boolean isReadonlyBody()
        Returns true if this message body is read only This means that message has been received and can not be modified
        Returns:
        true if the message is read only
      • isReadOnlyProperties

        protected boolean isReadOnlyProperties()
      • setReadOnlyBody

        protected void setReadOnlyBody​(boolean readonly)
      • setReadOnlyProperties

        protected void setReadOnlyProperties​(boolean readonly)
      • getRabbitDeliveryTag

        public long getRabbitDeliveryTag()
        returns the delivery tag for this message
        Returns:
        the delivery tag for this message
      • getSession

        public RMQSession getSession()
        Returns the session this object belongs to
        Returns:
        the session this object belongs to
      • getJMSMessageID

        public java.lang.String getJMSMessageID()
                                         throws jakarta.jms.JMSException
        Specified by:
        getJMSMessageID in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSMessageID

        public void setJMSMessageID​(java.lang.String id)
                             throws jakarta.jms.JMSException
        Specified by:
        setJMSMessageID in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSTimestamp

        public long getJMSTimestamp()
                             throws jakarta.jms.JMSException
        Specified by:
        getJMSTimestamp in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSTimestamp

        public void setJMSTimestamp​(long timestamp)
                             throws jakarta.jms.JMSException
        Specified by:
        setJMSTimestamp in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSCorrelationIDAsBytes

        public byte[] getJMSCorrelationIDAsBytes()
                                          throws jakarta.jms.JMSException
        Specified by:
        getJMSCorrelationIDAsBytes in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSCorrelationIDAsBytes

        public void setJMSCorrelationIDAsBytes​(byte[] correlationID)
                                        throws jakarta.jms.JMSException
        Specified by:
        setJMSCorrelationIDAsBytes in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSCorrelationID

        public void setJMSCorrelationID​(java.lang.String correlationID)
                                 throws jakarta.jms.JMSException
        Specified by:
        setJMSCorrelationID in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSCorrelationID

        public java.lang.String getJMSCorrelationID()
                                             throws jakarta.jms.JMSException
        Specified by:
        getJMSCorrelationID in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSReplyTo

        public jakarta.jms.Destination getJMSReplyTo()
                                              throws jakarta.jms.JMSException
        Specified by:
        getJMSReplyTo in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSReplyTo

        public void setJMSReplyTo​(jakarta.jms.Destination replyTo)
                           throws jakarta.jms.JMSException
        Specified by:
        setJMSReplyTo in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSDestination

        public jakarta.jms.Destination getJMSDestination()
                                                  throws jakarta.jms.JMSException
        Specified by:
        getJMSDestination in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSDestination

        public void setJMSDestination​(jakarta.jms.Destination destination)
                               throws jakarta.jms.JMSException
        Specified by:
        setJMSDestination in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSDeliveryMode

        public int getJMSDeliveryMode()
                               throws jakarta.jms.JMSException
        Specified by:
        getJMSDeliveryMode in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSDeliveryMode

        public void setJMSDeliveryMode​(int deliveryMode)
                                throws jakarta.jms.JMSException
        Specified by:
        setJMSDeliveryMode in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSRedelivered

        public boolean getJMSRedelivered()
                                  throws jakarta.jms.JMSException
        Specified by:
        getJMSRedelivered in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSRedelivered

        public void setJMSRedelivered​(boolean redelivered)
                               throws jakarta.jms.JMSException
        Specified by:
        setJMSRedelivered in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSType

        public java.lang.String getJMSType()
                                    throws jakarta.jms.JMSException
        Specified by:
        getJMSType in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSType

        public void setJMSType​(java.lang.String type)
                        throws jakarta.jms.JMSException
        Specified by:
        setJMSType in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSExpiration

        public long getJMSExpiration()
                              throws jakarta.jms.JMSException
        Specified by:
        getJMSExpiration in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSExpiration

        public void setJMSExpiration​(long expiration)
                              throws jakarta.jms.JMSException
        Specified by:
        setJMSExpiration in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getJMSPriority

        public int getJMSPriority()
                           throws jakarta.jms.JMSException
        Specified by:
        getJMSPriority in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSPriority

        public void setJMSPriority​(int priority)
                            throws jakarta.jms.JMSException
        Specified by:
        setJMSPriority in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • clearProperties

        public final void clearProperties()
                                   throws jakarta.jms.JMSException
        Specified by:
        clearProperties in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • propertyExists

        public boolean propertyExists​(java.lang.String name)
        Specified by:
        propertyExists in interface jakarta.jms.Message
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String name)
                                   throws jakarta.jms.JMSException
        Specified by:
        getBooleanProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getByteProperty

        public byte getByteProperty​(java.lang.String name)
                             throws jakarta.jms.JMSException
        Specified by:
        getByteProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getShortProperty

        public short getShortProperty​(java.lang.String name)
                               throws jakarta.jms.JMSException
        Specified by:
        getShortProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getIntProperty

        public int getIntProperty​(java.lang.String name)
                           throws jakarta.jms.JMSException
        Specified by:
        getIntProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getLongProperty

        public long getLongProperty​(java.lang.String name)
                             throws jakarta.jms.JMSException
        Specified by:
        getLongProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getFloatProperty

        public float getFloatProperty​(java.lang.String name)
                               throws jakarta.jms.JMSException
        Specified by:
        getFloatProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getDoubleProperty

        public double getDoubleProperty​(java.lang.String name)
                                 throws jakarta.jms.JMSException
        Specified by:
        getDoubleProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getStringProperty

        public java.lang.String getStringProperty​(java.lang.String name)
                                           throws jakarta.jms.JMSException
        Specified by:
        getStringProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getObjectProperty

        public java.lang.Object getObjectProperty​(java.lang.String name)
                                           throws jakarta.jms.JMSException
        Specified by:
        getObjectProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getPropertyNames

        public java.util.Enumeration<?> getPropertyNames()
                                                  throws jakarta.jms.JMSException
        Specified by:
        getPropertyNames in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setBooleanProperty

        public void setBooleanProperty​(java.lang.String name,
                                       boolean value)
                                throws jakarta.jms.JMSException
        Specified by:
        setBooleanProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setByteProperty

        public void setByteProperty​(java.lang.String name,
                                    byte value)
                             throws jakarta.jms.JMSException
        Specified by:
        setByteProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setShortProperty

        public void setShortProperty​(java.lang.String name,
                                     short value)
                              throws jakarta.jms.JMSException
        Specified by:
        setShortProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setIntProperty

        public void setIntProperty​(java.lang.String name,
                                   int value)
                            throws jakarta.jms.JMSException
        Specified by:
        setIntProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setLongProperty

        public void setLongProperty​(java.lang.String name,
                                    long value)
                             throws jakarta.jms.JMSException
        Specified by:
        setLongProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setFloatProperty

        public void setFloatProperty​(java.lang.String name,
                                     float value)
                              throws jakarta.jms.JMSException
        Specified by:
        setFloatProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setDoubleProperty

        public void setDoubleProperty​(java.lang.String name,
                                      double value)
                               throws jakarta.jms.JMSException
        Specified by:
        setDoubleProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setStringProperty

        public void setStringProperty​(java.lang.String name,
                                      java.lang.String value)
                               throws jakarta.jms.JMSException
        Specified by:
        setStringProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setObjectProperty

        public void setObjectProperty​(java.lang.String name,
                                      java.lang.Object value)
                               throws jakarta.jms.JMSException
        Specified by:
        setObjectProperty in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • acknowledge

        public void acknowledge()
                         throws jakarta.jms.JMSException
        Although the JavaDoc implies otherwise, this call acknowledges all unacknowledged messages on the message's session.

        The JavaDoc says:

        A client may individually acknowledge each message as it is consumed, or it may choose to acknowledge messages as an application-defined group (which is done by calling acknowledge on the last received message of the group, thereby acknowledging all messages consumed by the session.)

        ...but there is no way to do either of these things, as is explained by the specification[1].

        [1] JMS 1.1 spec Section 11.3.2.2.

        Specified by:
        acknowledge in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
        See Also:
        RMQSession.acknowledgeMessage(RMQMessage)
      • clearBody

        public final void clearBody()
                             throws jakarta.jms.JMSException
        Specified by:
        clearBody in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • clearBodyInternal

        protected abstract void clearBodyInternal()
                                           throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException
      • writeBody

        protected abstract void writeBody​(java.io.ObjectOutput out,
                                          java.io.ByteArrayOutputStream bout)
                                   throws java.io.IOException
        Invoked when toByteArray() is called to create a byte[] from a message. Each subclass must implement this, but ONLY write its specific body. All the properties defined in Message will be written by the parent class.
        Parameters:
        out - - the output stream to which the structured part of message body (scalar types) is written
        bout - - the output stream to which the un-structured part of message body (explicit bytes) is written
        Throws:
        java.io.IOException - if the body can not be written
      • writeAmqpBody

        protected abstract void writeAmqpBody​(java.io.ByteArrayOutputStream out)
                                       throws java.io.IOException
        Invoked when toAmqpByteArray() is called to create a byte[] from a message. Each subclass must implement this, but ONLY write its specific body.
        Parameters:
        out - - the output stream to which the message body is written
        Throws:
        java.io.IOException - if the body can not be written
      • readBody

        protected abstract void readBody​(java.io.ObjectInput inputStream,
                                         java.io.ByteArrayInputStream bin)
                                  throws java.io.IOException,
                                         java.lang.ClassNotFoundException
        Invoked when a message is being deserialized to read and decode the message body. The implementing class should only read its body from this stream. If any exception is thrown, the message will not have been delivered.
        Parameters:
        inputStream - - the stream to read its body from
        bin - - the underlying byte input stream
        Throws:
        java.io.IOException - if a read error occurs on the input stream
        java.lang.ClassNotFoundException - if the object class cannot be found
      • readAmqpBody

        protected abstract void readAmqpBody​(byte[] barr)
        Invoked when an AMQP message is being transformed into a RMQMessage The implementing class should only read its body by this method
        Parameters:
        barr - - the byte array payload of the AMQP message
      • doNotDeclareReplyToDestination

        public static void doNotDeclareReplyToDestination​(jakarta.jms.Message message)
                                                   throws jakarta.jms.JMSException
        Indicates to not declare a reply-to RMQDestination.

        This is used for inbound messages, when the reply-to destination is supposed to be already created. This avoids trying to create a second time a temporary queue.

        Parameters:
        message -
        Throws:
        jakarta.jms.JMSException
        Since:
        1.11.0
      • isAmqpWritable

        public abstract boolean isAmqpWritable()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getInternalID

        public java.lang.String getInternalID()
        Returns the unique ID for this message. This will return null unless the message has been sent on the wire
        Returns:
        internal message ID
      • writePrimitive

        protected static void writePrimitive​(java.lang.Object s,
                                             java.io.ObjectOutput out)
                                      throws java.io.IOException,
                                             jakarta.jms.MessageFormatException
        Utility method used to be able to write primitives and objects to a data stream without keeping track of order and type.

        This also allows any Object to be written.

        The purpose of this method is to optimise the writing of a primitive that is represented as an object by only writing the type and the primitive value to the stream.

        Parameters:
        s - the primitive to be written
        out - the stream to write the primitive to.
        Throws:
        java.io.IOException - if an I/O error occurs
        jakarta.jms.MessageFormatException - if message cannot be parsed
      • writePrimitive

        protected static void writePrimitive​(java.lang.Object s,
                                             java.io.ObjectOutput out,
                                             boolean allowSerializable)
                                      throws java.io.IOException,
                                             jakarta.jms.MessageFormatException
        Throws:
        java.io.IOException
        jakarta.jms.MessageFormatException
      • readPrimitive

        protected static java.lang.Object readPrimitive​(java.io.ObjectInput in)
                                                 throws java.io.IOException,
                                                        java.lang.ClassNotFoundException
        Utility method to read objects from a stream. These objects must have been written with the method writePrimitive(Object, ObjectOutput) otherwise deserialization will fail and an IOException will be thrown
        Parameters:
        in - the stream to read from
        Returns:
        the Object read
        Throws:
        java.io.IOException - if an I/O error occurs
        java.lang.ClassNotFoundException - if a class of serialized object cannot be found
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException
      • copyAttributes

        protected static void copyAttributes​(RMQMessage rmqMessage,
                                             jakarta.jms.Message message)
                                      throws jakarta.jms.JMSException
        Assign generic attributes.
         “rmqMessage = (RMQMessage) message;”

        With conversion as appropriate.

        Parameters:
        rmqMessage - message filled in with attributes
        message - message from which attributes are gained.
        Throws:
        jakarta.jms.JMSException - if attributes cannot be copied
      • getJMSDeliveryTime

        public long getJMSDeliveryTime()
                                throws jakarta.jms.JMSException
        Specified by:
        getJMSDeliveryTime in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • setJMSDeliveryTime

        public void setJMSDeliveryTime​(long deliveryTime)
                                throws jakarta.jms.JMSException
        Specified by:
        setJMSDeliveryTime in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • getBody

        public <T> T getBody​(java.lang.Class<T> c)
                      throws jakarta.jms.JMSException
        Specified by:
        getBody in interface jakarta.jms.Message
        Throws:
        jakarta.jms.JMSException
      • doGetBody

        protected abstract <T> T doGetBody​(java.lang.Class<T> c)
                                    throws jakarta.jms.JMSException
        Throws:
        jakarta.jms.JMSException