Class SQSMessage
- All Implemented Interfaces:
jakarta.jms.Message
- Direct Known Subclasses:
SQSBytesMessage
,SQSObjectMessage
,SQSTextMessage
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 inSQSMessageConsumerPrefetch
, this can be set to true although user never received the message. This is set based on SQS ApproximateReceiveCount attributeJMSDestination
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class is used fulfill object value, corresponding SQS message attribute type and message attribute string value.static class
Copied from org.apache.activemq.util.TypeConversionSupport to provide the same property support provided by activemq without creating a dependency on activemq. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from interface jakarta.jms.Message
DEFAULT_DELIVERY_DELAY, DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Acknowledges message(s).protected void
protected void
void
Clears out the message body.void
Clears a message's properties and set the write permissions for properties.protected static jakarta.jms.JMSException
protected static jakarta.jms.MessageFormatException
<T> T
boolean
getBooleanProperty
(String name) Returns the value of theboolean
property with the specified name.byte
getByteProperty
(String name) Returns the value of thebyte
property with the specified name.double
getDoubleProperty
(String name) Returns the value of thedouble
property with the specified name.float
getFloatProperty
(String name) Returns the value of thefloat
property with the specified name.int
getIntProperty
(String name) Returns the value of theint
property with the specified name.byte[]
int
long
jakarta.jms.Destination
Gets the Destination object for this message.long
Gets the message ID.Returns the property value with message attribute to object property conversions took place.int
boolean
jakarta.jms.Destination
long
long
getLongProperty
(String name) Returns the value of thelong
property with the specified name.getObjectProperty
(String name) Returns the value of the Java object property with the specified name.Returns anEnumeration
of all the property names.Get queueUrl the message came from.Get SQS Message receiptHandle.short
getShortProperty
(String name) Returns the value of theshort
property with the specified name.Get SQS Message Deduplication Id (applicable for FIFO queues, available also as JMS property 'JMS_SQS_DeduplicationId')Get SQS Message Group Id (applicable for FIFO queues, available also as JMS property 'JMSXGroupId')Get SQS Message Id.Get SQS Message Sequence Number (applicable for FIFO queues, available also as JMS property 'JMS_SQS_SequenceNumber')getStringProperty
(String name) Returns the value of theString
property with the specified name.boolean
boolean
propertyExists
(String name) Indicates whether a property value exists for the given property name.protected void
setBodyWritePermissions
(boolean enable) void
setBooleanProperty
(String name, boolean value) Sets aboolean
property value with the specified name into the message.void
setByteProperty
(String name, byte value) Sets abyte
property value with the specified name into the message.void
setDoubleProperty
(String name, double value) Sets adouble
property value with the specified name into the message.void
setFloatProperty
(String name, float value) Sets afloat
property value with the specified name into the message.void
setIntProperty
(String name, int value) Sets aint
property value with the specified name into the message.void
setJMSCorrelationID
(String correlationID) void
setJMSCorrelationIDAsBytes
(byte[] correlationID) void
setJMSDeliveryMode
(int deliveryMode) void
setJMSDeliveryTime
(long deliveryTime) void
setJMSDestination
(jakarta.jms.Destination destination) Sets the Destination object for this message.void
setJMSExpiration
(long expiration) void
Sets the message ID.void
setJMSPriority
(int priority) void
setJMSRedelivered
(boolean redelivered) void
setJMSReplyTo
(jakarta.jms.Destination replyTo) void
setJMSTimestamp
(long timestamp) void
setJMSType
(String type) void
setLongProperty
(String name, long value) Sets along
property value with the specified name into the message.void
setObjectProperty
(String name, Object value) Sets a Java object property value with the specified name into the message.void
setSequenceNumber
(String sequenceNumber) This method sets the JMS_SQS_SEQUENCE_NUMBER property on the message.void
setShortProperty
(String name, short value) Sets ashort
property value with the specified name into the message.void
setSQSMessageId
(String sqsMessageID) Set SQS Message Id, used on send.void
setStringProperty
(String name, String value) Sets aString
property value with the specified name into the message.
-
Field Details
-
BYTE_MESSAGE_TYPE
- See Also:
-
OBJECT_MESSAGE_TYPE
- See Also:
-
TEXT_MESSAGE_TYPE
- See Also:
-
JMS_SQS_MESSAGE_TYPE
- See Also:
-
JMS_SQS_REPLY_TO_QUEUE_NAME
- See Also:
-
JMS_SQS_REPLY_TO_QUEUE_URL
- See Also:
-
JMS_SQS_CORRELATION_ID
- See Also:
-
-
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
-
convertExceptionToMessageFormatException
protected static jakarta.jms.MessageFormatException convertExceptionToMessageFormatException(Exception e) -
setBodyWritePermissions
protected void setBodyWritePermissions(boolean enable) -
getSQSMessageGroupId
Get SQS Message Group Id (applicable for FIFO queues, available also as JMS property 'JMSXGroupId')- Throws:
jakarta.jms.JMSException
-
getSQSMessageDeduplicationId
Get SQS Message Deduplication Id (applicable for FIFO queues, available also as JMS property 'JMS_SQS_DeduplicationId')- Throws:
jakarta.jms.JMSException
-
getSQSMessageSequenceNumber
Get SQS Message Sequence Number (applicable for FIFO queues, available also as JMS property 'JMS_SQS_SequenceNumber')- Throws:
jakarta.jms.JMSException
-
getSQSMessageId
Get SQS Message Id.- Returns:
- SQS Message Id.
-
setSQSMessageId
Set SQS Message Id, used on send.- Parameters:
sqsMessageID
- messageId assigned by SQS during send.- Throws:
jakarta.jms.JMSException
-
getReceiptHandle
Get SQS Message receiptHandle.- Returns:
- SQS Message receiptHandle.
-
getQueueUrl
Get queueUrl the message came from.- Returns:
- queueUrl.
-
getJMSMessageID
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 interfacejakarta.jms.Message
- Returns:
- the ID of the message.
- Throws:
jakarta.jms.JMSException
-
setJMSMessageID
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 interfacejakarta.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 interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSTimestamp
public void setJMSTimestamp(long timestamp) throws jakarta.jms.JMSException - Specified by:
setJMSTimestamp
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSCorrelationIDAsBytes
public byte[] getJMSCorrelationIDAsBytes() throws jakarta.jms.JMSException- Specified by:
getJMSCorrelationIDAsBytes
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSCorrelationIDAsBytes
public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws jakarta.jms.JMSException - Specified by:
setJMSCorrelationIDAsBytes
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSCorrelationID
- Specified by:
setJMSCorrelationID
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSCorrelationID
- Specified by:
getJMSCorrelationID
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSReplyTo
public jakarta.jms.Destination getJMSReplyTo() throws jakarta.jms.JMSException- Specified by:
getJMSReplyTo
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSReplyTo
public void setJMSReplyTo(jakarta.jms.Destination replyTo) throws jakarta.jms.JMSException - Specified by:
setJMSReplyTo
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSDestination
public jakarta.jms.Destination getJMSDestination() throws jakarta.jms.JMSExceptionGets 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 interfacejakarta.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 interfacejakarta.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 interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSDeliveryMode
public void setJMSDeliveryMode(int deliveryMode) throws jakarta.jms.JMSException - Specified by:
setJMSDeliveryMode
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSRedelivered
public boolean getJMSRedelivered() throws jakarta.jms.JMSException- Specified by:
getJMSRedelivered
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSRedelivered
public void setJMSRedelivered(boolean redelivered) throws jakarta.jms.JMSException - Specified by:
setJMSRedelivered
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSType
- Specified by:
getJMSType
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSType
- Specified by:
setJMSType
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSExpiration
public long getJMSExpiration() throws jakarta.jms.JMSException- Specified by:
getJMSExpiration
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSExpiration
public void setJMSExpiration(long expiration) throws jakarta.jms.JMSException - Specified by:
setJMSExpiration
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSDeliveryTime
public long getJMSDeliveryTime() throws jakarta.jms.JMSException- Specified by:
getJMSDeliveryTime
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSDeliveryTime
public void setJMSDeliveryTime(long deliveryTime) throws jakarta.jms.JMSException - Specified by:
setJMSDeliveryTime
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
getJMSPriority
public int getJMSPriority() throws jakarta.jms.JMSException- Specified by:
getJMSPriority
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setJMSPriority
public void setJMSPriority(int priority) throws jakarta.jms.JMSException - Specified by:
setJMSPriority
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
clearProperties
public void clearProperties() throws jakarta.jms.JMSExceptionClears 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 interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
propertyExists
Indicates whether a property value exists for the given property name.- Specified by:
propertyExists
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property.- Returns:
- true if the property exists.
- Throws:
jakarta.jms.JMSException
-
getBooleanProperty
Returns the value of theboolean
property with the specified name.- Specified by:
getBooleanProperty
in interfacejakarta.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
Returns the value of thebyte
property with the specified name.- Specified by:
getByteProperty
in interfacejakarta.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
Returns the value of theshort
property with the specified name.- Specified by:
getShortProperty
in interfacejakarta.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
Returns the value of theint
property with the specified name.- Specified by:
getIntProperty
in interfacejakarta.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
Returns the value of thelong
property with the specified name.- Specified by:
getLongProperty
in interfacejakarta.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
Returns the value of thefloat
property with the specified name.- Specified by:
getFloatProperty
in interfacejakarta.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
Returns the value of thedouble
property with the specified name.- Specified by:
getDoubleProperty
in interfacejakarta.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
Returns the value of theString
property with the specified name.- Specified by:
getStringProperty
in interfacejakarta.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
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 interfacejakarta.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
, anInteger
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
Returns anEnumeration
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 interfacejakarta.jms.Message
- Returns:
- an enumeration of all the names of property values.
- Throws:
jakarta.jms.JMSException
- On internal error.
-
setBooleanProperty
Sets aboolean
property value with the specified name into the message.- Specified by:
setBooleanProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Theboolean
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
Sets abyte
property value with the specified name into the message.- Specified by:
setByteProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Thebyte
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
Sets ashort
property value with the specified name into the message.- Specified by:
setShortProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Theshort
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
Sets aint
property value with the specified name into the message.- Specified by:
setIntProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Theint
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
Sets along
property value with the specified name into the message.- Specified by:
setLongProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Thelong
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
Sets afloat
property value with the specified name into the message.- Specified by:
setFloatProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Thefloat
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
Sets adouble
property value with the specified name into the message.- Specified by:
setDoubleProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- Thedouble
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
Sets aString
property value with the specified name into the message.- Specified by:
setStringProperty
in interfacejakarta.jms.Message
- Parameters:
name
- The name of the property to set.value
- TheString
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
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 interfacejakarta.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.JMSExceptionAcknowledges 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 interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
- On Internal errorIllegalStateException
- If this method is called on a closed session.- See Also:
-
clearBody
public void clearBody() throws jakarta.jms.JMSExceptionClears 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 interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
- If directly called
-
getBody
- Specified by:
getBody
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
isBodyAssignableTo
- Specified by:
isBodyAssignableTo
in interfacejakarta.jms.Message
- Throws:
jakarta.jms.JMSException
-
setSequenceNumber
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
-