Class SQSMessage

  • All Implemented Interfaces:
    javax.jms.Message
    Direct Known Subclasses:
    SQSBytesMessage, SQSObjectMessage, SQSTextMessage

    public class SQSMessage
    extends Object
    implements javax.jms.Message
    The SQSMessage is the root class of all SQS JMS messages and implements JMS Message interface.

    Not all message headers are supported at this time:

    • JMSMessageID is always assigned as SQS provided message id.
    • JMSRedelivered is set to true if SQS delivers the message more than once. This not necessarily mean that the user received message more than once, but rather SQS attempted to deliver it more than once. Due to prefetching used in SQSMessageConsumerPrefetch, this can be set to true although user never received the message. This is set based on SQS ApproximateReceiveCount attribute
    • JMSDestination
    • is the destination object which message is sent to and received from.

    JMSXDeliveryCount reserved property is supported and set based on the approximate receive count observed on the SQS side.

    • Method Detail

      • checkPropertyWritePermissions

        protected void checkPropertyWritePermissions()
                                              throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • checkBodyWritePermissions

        protected void checkBodyWritePermissions()
                                          throws javax.jms.JMSException
        Throws:
        javax.jms.JMSException
      • convertExceptionToJMSException

        protected static javax.jms.JMSException convertExceptionToJMSException​(Exception e)
      • convertExceptionToMessageFormatException

        protected static javax.jms.MessageFormatException convertExceptionToMessageFormatException​(Exception e)
      • setBodyWritePermissions

        protected void setBodyWritePermissions​(boolean enable)
      • getSQSMessageGroupId

        public String getSQSMessageGroupId()
                                    throws javax.jms.JMSException
        Get SQS Message Group Id (applicable for FIFO queues, available also as JMS property 'JMSXGroupId')
        Throws:
        javax.jms.JMSException
      • getSQSMessageDeduplicationId

        public String getSQSMessageDeduplicationId()
                                            throws javax.jms.JMSException
        Get SQS Message Deduplication Id (applicable for FIFO queues, available also as JMS property 'JMS_SQS_DeduplicationId')
        Throws:
        javax.jms.JMSException
      • getSQSMessageSequenceNumber

        public String getSQSMessageSequenceNumber()
                                           throws javax.jms.JMSException
        Get SQS Message Sequence Number (applicable for FIFO queues, available also as JMS property 'JMS_SQS_SequenceNumber')
        Throws:
        javax.jms.JMSException
      • getSQSMessageId

        public String getSQSMessageId()
        Get SQS Message Id.
        Returns:
        SQS Message Id.
      • setSQSMessageId

        public void setSQSMessageId​(String sqsMessageID)
                             throws javax.jms.JMSException
        Set SQS Message Id, used on send.
        Parameters:
        sqsMessageID - messageId assigned by SQS during send.
        Throws:
        javax.jms.JMSException
      • getReceiptHandle

        public String getReceiptHandle()
        Get SQS Message receiptHandle.
        Returns:
        SQS Message receiptHandle.
      • getQueueUrl

        public String getQueueUrl()
        Get queueUrl the message came from.
        Returns:
        queueUrl.
      • getJMSMessageID

        public String getJMSMessageID()
                               throws javax.jms.JMSException
        Gets the message ID.

        The JMSMessageID header field contains a value that uniquely identifies each message sent by a provider. It is set to SQS messageId with the prefix 'ID:'.

        Specified by:
        getJMSMessageID in interface javax.jms.Message
        Returns:
        the ID of the message.
        Throws:
        javax.jms.JMSException
      • setJMSMessageID

        public void setJMSMessageID​(String id)
                             throws javax.jms.JMSException
        Sets the message ID. It should have prefix 'ID:'.

        Set when a message is sent. This method can be used to change the value for a message that has been received.

        Specified by:
        setJMSMessageID in interface javax.jms.Message
        Parameters:
        id - The ID of the message.
        Throws:
        javax.jms.JMSException
      • getJMSTimestamp

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

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

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

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

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

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

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

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

        public javax.jms.Destination getJMSDestination()
                                                throws javax.jms.JMSException
        Gets the Destination object for this message.

        The JMSDestination header field contains the destination to which the message is being sent.

        When a message is sent, this field is ignored. After completion of the send or publish method, the field holds the destination specified by the method.

        When a message is received, its JMSDestination value must be equivalent to the value assigned when it was sent.

        Specified by:
        getJMSDestination in interface javax.jms.Message
        Returns:
        The destination of this message.
        Throws:
        javax.jms.JMSException
      • setJMSDestination

        public void setJMSDestination​(javax.jms.Destination destination)
                               throws javax.jms.JMSException
        Sets the Destination object for this message.

        Set when a message is sent. This method can be used to change the value for a message that has been received.

        Specified by:
        setJMSDestination in interface javax.jms.Message
        Parameters:
        destination - The destination for this message.
        Throws:
        javax.jms.JMSException
      • getJMSDeliveryMode

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

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

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

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

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

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

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

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

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

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

        public void clearProperties()
                             throws javax.jms.JMSException
        Clears a message's properties and set the write permissions for properties. The message's header fields and body are not cleared.
        Specified by:
        clearProperties in interface javax.jms.Message
        Throws:
        javax.jms.JMSException
      • propertyExists

        public boolean propertyExists​(String name)
                               throws javax.jms.JMSException
        Indicates whether a property value exists for the given property name.
        Specified by:
        propertyExists in interface javax.jms.Message
        Parameters:
        name - The name of the property.
        Returns:
        true if the property exists.
        Throws:
        javax.jms.JMSException
      • getBooleanProperty

        public boolean getBooleanProperty​(String name)
                                   throws javax.jms.JMSException
        Returns the value of the boolean property with the specified name.
        Specified by:
        getBooleanProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the boolean property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name is null.
      • getByteProperty

        public byte getByteProperty​(String name)
                             throws javax.jms.JMSException
        Returns the value of the byte property with the specified name.
        Specified by:
        getByteProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the byte property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name is null.
        NumberFormatException - When property value is null.
      • getShortProperty

        public short getShortProperty​(String name)
                               throws javax.jms.JMSException
        Returns the value of the short property with the specified name.
        Specified by:
        getShortProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the short property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name is null.
        NumberFormatException - When property value is null.
      • getIntProperty

        public int getIntProperty​(String name)
                           throws javax.jms.JMSException
        Returns the value of the int property with the specified name.
        Specified by:
        getIntProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the int property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name is null.
        NumberFormatException - When property value is null.
      • getLongProperty

        public long getLongProperty​(String name)
                             throws javax.jms.JMSException
        Returns the value of the long property with the specified name.
        Specified by:
        getLongProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the long property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name is null.
        NumberFormatException - When property value is null.
      • getFloatProperty

        public float getFloatProperty​(String name)
                               throws javax.jms.JMSException
        Returns the value of the float property with the specified name.
        Specified by:
        getFloatProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the float property value for the specified name.
        Throws:
        javax.jms.JMSException - Wn internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name or value is null.
      • getDoubleProperty

        public double getDoubleProperty​(String name)
                                 throws javax.jms.JMSException
        Returns the value of the double property with the specified name.
        Specified by:
        getDoubleProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the double property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name or value is null.
      • getStringProperty

        public String getStringProperty​(String name)
                                 throws javax.jms.JMSException
        Returns the value of the String property with the specified name.
        Specified by:
        getStringProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the String property value for the specified name.
        Throws:
        javax.jms.JMSException - On internal error.
        javax.jms.MessageFormatException - If the property cannot be converted to the specified type.
        NullPointerException - When property name is null.
      • getObjectProperty

        public Object getObjectProperty​(String name)
                                 throws javax.jms.JMSException
        Returns the value of the Java object property with the specified name.

        This method can be used to return, in boxed format, an object that has been stored as a property in the message with the equivalent setObjectProperty method call, or its equivalent primitive setter method.

        Specified by:
        getObjectProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to get.
        Returns:
        the Java object property value with the specified name, in boxed format (for example, if the property was set as an int, an Integer is returned); if there is no property by this name, a null value is returned.
        Throws:
        javax.jms.JMSException - On internal error.
      • getJMSMessagePropertyValue

        public SQSMessage.JMSMessagePropertyValue getJMSMessagePropertyValue​(String name)
                                                                      throws javax.jms.JMSException
        Returns the property value with message attribute to object property conversions took place.

        Parameters:
        name - The name of the property to get.
        Returns:
        JMSMessagePropertyValue with object value and corresponding SQS message attribute type and message attribute string value.
        Throws:
        javax.jms.JMSException - On internal error.
      • getPropertyNames

        public Enumeration<String> getPropertyNames()
                                             throws javax.jms.JMSException
        Returns an Enumeration of all the property names.

        Note that JMS standard header fields are not considered properties and are not returned in this enumeration.

        Specified by:
        getPropertyNames in interface javax.jms.Message
        Returns:
        an enumeration of all the names of property values.
        Throws:
        javax.jms.JMSException - On internal error.
      • setBooleanProperty

        public void setBooleanProperty​(String name,
                                       boolean value)
                                throws javax.jms.JMSException
        Sets a boolean property value with the specified name into the message.
        Specified by:
        setBooleanProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The boolean value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setByteProperty

        public void setByteProperty​(String name,
                                    byte value)
                             throws javax.jms.JMSException
        Sets a byte property value with the specified name into the message.
        Specified by:
        setByteProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The byte value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setShortProperty

        public void setShortProperty​(String name,
                                     short value)
                              throws javax.jms.JMSException
        Sets a short property value with the specified name into the message.
        Specified by:
        setShortProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The short value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setIntProperty

        public void setIntProperty​(String name,
                                   int value)
                            throws javax.jms.JMSException
        Sets a int property value with the specified name into the message.
        Specified by:
        setIntProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The int value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setLongProperty

        public void setLongProperty​(String name,
                                    long value)
                             throws javax.jms.JMSException
        Sets a long property value with the specified name into the message.
        Specified by:
        setLongProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The long value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setFloatProperty

        public void setFloatProperty​(String name,
                                     float value)
                              throws javax.jms.JMSException
        Sets a float property value with the specified name into the message.
        Specified by:
        setFloatProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The float value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setDoubleProperty

        public void setDoubleProperty​(String name,
                                      double value)
                               throws javax.jms.JMSException
        Sets a double property value with the specified name into the message.
        Specified by:
        setDoubleProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The double value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setStringProperty

        public void setStringProperty​(String name,
                                      String value)
                               throws javax.jms.JMSException
        Sets a String property value with the specified name into the message.
        Specified by:
        setStringProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The String value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • setObjectProperty

        public void setObjectProperty​(String name,
                                      Object value)
                               throws javax.jms.JMSException
        Sets a Java object property value with the specified name into the message.

        Note that this method works only for the boxed primitive object types (Integer, Double, Long ...) and String objects.

        Specified by:
        setObjectProperty in interface javax.jms.Message
        Parameters:
        name - The name of the property to set.
        value - The object value of the property to set.
        Throws:
        javax.jms.JMSException - On internal error.
        IllegalArgumentException - If the name or value is null or empty string.
        javax.jms.MessageFormatException - If the object is invalid type.
        javax.jms.MessageNotWriteableException - If properties are read-only.
      • acknowledge

        public void acknowledge()
                         throws javax.jms.JMSException

        Acknowledges message(s).

        A client may individually acknowledge each message as it is consumed, or it may choose to acknowledge multiple messages based on acknowledge mode, which in turn might might acknowledge all messages consumed by the session.

        Messages that have been received but not acknowledged may be redelivered.

        If the session is closed, messages cannot be acknowledged.

        If only the consumer is closed, messages can still be acknowledged.

        Specified by:
        acknowledge in interface javax.jms.Message
        Throws:
        javax.jms.JMSException - On Internal error
        IllegalStateException - If this method is called on a closed session.
        See Also:
        AcknowledgeMode
      • clearBody

        public void clearBody()
                       throws javax.jms.JMSException

        Clears out the message body. Clearing a message's body does not clear its header values or property entries.

        This method cannot be called directly instead the implementation on the subclasses should be used.

        Specified by:
        clearBody in interface javax.jms.Message
        Throws:
        javax.jms.JMSException - If directly called
      • setSequenceNumber

        public void setSequenceNumber​(String sequenceNumber)
                               throws javax.jms.JMSException
        This method sets the JMS_SQS_SEQUENCE_NUMBER property on the message. It is exposed explicitly here, so that it can be invoked even on read-only message object obtained through receing a message. This support the use case of send a received message by using the same JMSMessage object.
        Parameters:
        sequenceNumber - Sequence number to set. If null or empty, the stored sequence number will be removed.
        Throws:
        javax.jms.JMSException