Class SQSMessage

java.lang.Object
com.amazon.sqs.javamessaging.message.SQSMessage
All Implemented Interfaces:
jakarta.jms.Message
Direct Known Subclasses:
SQSBytesMessage, SQSObjectMessage, SQSTextMessage

public class SQSMessage extends Object implements jakarta.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 reception count observed on the SQS side.

  • Field Details

  • Method Details

    • checkPropertyWritePermissions

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

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

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

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

      protected void setBodyWritePermissions(boolean enable)
    • getSQSMessageGroupId

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

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

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

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

      public void setSQSMessageId(String sqsMessageID) throws jakarta.jms.JMSException
      Set SQS Message Id, used on send.
      Parameters:
      sqsMessageID - messageId assigned by SQS during send.
      Throws:
      jakarta.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 jakarta.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 jakarta.jms.Message
      Returns:
      the ID of the message.
      Throws:
      jakarta.jms.JMSException
    • setJMSMessageID

      public void setJMSMessageID(String id) throws jakarta.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 jakarta.jms.Message
      Parameters:
      id - The ID of the 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(String correlationID) throws jakarta.jms.JMSException
      Specified by:
      setJMSCorrelationID in interface jakarta.jms.Message
      Throws:
      jakarta.jms.JMSException
    • getJMSCorrelationID

      public 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
      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 jakarta.jms.Message
      Returns:
      The destination of this message.
      Throws:
      jakarta.jms.JMSException
    • setJMSDestination

      public void setJMSDestination(jakarta.jms.Destination destination) throws jakarta.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 jakarta.jms.Message
      Parameters:
      destination - The destination for this 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 String getJMSType() throws jakarta.jms.JMSException
      Specified by:
      getJMSType in interface jakarta.jms.Message
      Throws:
      jakarta.jms.JMSException
    • setJMSType

      public void setJMSType(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
    • 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
    • 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 void clearProperties() throws jakarta.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 jakarta.jms.Message
      Throws:
      jakarta.jms.JMSException
    • propertyExists

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

      public boolean getBooleanProperty(String name) throws jakarta.jms.JMSException
      Returns the value of the boolean property with the specified name.
      Specified by:
      getBooleanProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the boolean property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the byte property with the specified name.
      Specified by:
      getByteProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the byte property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the short property with the specified name.
      Specified by:
      getShortProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the short property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the int property with the specified name.
      Specified by:
      getIntProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the int property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the long property with the specified name.
      Specified by:
      getLongProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the long property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the float property with the specified name.
      Specified by:
      getFloatProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the float property value for the specified name.
      Throws:
      jakarta.jms.JMSException - Wn internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the double property with the specified name.
      Specified by:
      getDoubleProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the double property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.jms.JMSException
      Returns the value of the String property with the specified name.
      Specified by:
      getStringProperty in interface jakarta.jms.Message
      Parameters:
      name - The name of the property to get.
      Returns:
      the String property value for the specified name.
      Throws:
      jakarta.jms.JMSException - On internal error.
      jakarta.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 jakarta.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 jakarta.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:
      jakarta.jms.JMSException - On internal error.
    • getJMSMessagePropertyValue

      public SQSMessage.JMSMessagePropertyValue getJMSMessagePropertyValue(String name) throws jakarta.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:
      jakarta.jms.JMSException - On internal error.
    • getPropertyNames

      public Enumeration<String> getPropertyNames() throws jakarta.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 jakarta.jms.Message
      Returns:
      an enumeration of all the names of property values.
      Throws:
      jakarta.jms.JMSException - On internal error.
    • setBooleanProperty

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

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

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

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

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

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

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

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

      public void setObjectProperty(String name, Object value) throws jakarta.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 jakarta.jms.Message
      Parameters:
      name - The name of the property to set.
      value - The object value of the property to set.
      Throws:
      jakarta.jms.JMSException - On internal error.
      IllegalArgumentException - If the name or value is null or empty string.
      jakarta.jms.MessageFormatException - If the object is invalid type.
      jakarta.jms.MessageNotWriteableException - If properties are read-only.
    • acknowledge

      public void acknowledge() throws jakarta.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 jakarta.jms.Message
      Throws:
      jakarta.jms.JMSException - On Internal error
      IllegalStateException - If this method is called on a closed session.
      See Also:
    • clearBody

      public void clearBody() throws jakarta.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 jakarta.jms.Message
      Throws:
      jakarta.jms.JMSException - If directly called
    • getBody

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

      public boolean isBodyAssignableTo(Class c) throws jakarta.jms.JMSException
      Specified by:
      isBodyAssignableTo in interface jakarta.jms.Message
      Throws:
      jakarta.jms.JMSException
    • setSequenceNumber

      public void setSequenceNumber(String sequenceNumber) throws jakarta.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 receiving 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:
      jakarta.jms.JMSException