Class SQSMessage
- All Implemented Interfaces:
jakarta.jms.Message
- Direct Known Subclasses:
SQSBytesMessage,SQSObjectMessage,SQSTextMessage
Not all message headers are supported at this time:
JMSMessageIDis always assigned as SQS provided message id.JMSRedeliveredis 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 attributeJMSDestinationis 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 classThis class is used fulfill object value, corresponding SQS message attribute type and message attribute string value.static classCopied 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 Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface jakarta.jms.Message
DEFAULT_DELIVERY_DELAY, DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE -
Method Summary
Modifier and TypeMethodDescriptionvoidAcknowledges message(s).protected voidprotected voidvoidClears out the message body.voidClears a message's properties and set the write permissions for properties.protected static jakarta.jms.JMSExceptionprotected static jakarta.jms.MessageFormatException<T> TbooleangetBooleanProperty(String name) Returns the value of thebooleanproperty with the specified name.bytegetByteProperty(String name) Returns the value of thebyteproperty with the specified name.doublegetDoubleProperty(String name) Returns the value of thedoubleproperty with the specified name.floatgetFloatProperty(String name) Returns the value of thefloatproperty with the specified name.intgetIntProperty(String name) Returns the value of theintproperty with the specified name.byte[]intlongjakarta.jms.DestinationGets the Destination object for this message.longGets the message ID.Returns the property value with message attribute to object property conversions took place.intbooleanjakarta.jms.DestinationlonglonggetLongProperty(String name) Returns the value of thelongproperty with the specified name.getObjectProperty(String name) Returns the value of the Java object property with the specified name.Returns anEnumerationof all the property names.Get queueUrl the message came from.Get SQS Message receiptHandle.shortgetShortProperty(String name) Returns the value of theshortproperty 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 theStringproperty with the specified name.booleanbooleanpropertyExists(String name) Indicates whether a property value exists for the given property name.protected voidsetBodyWritePermissions(boolean enable) voidsetBooleanProperty(String name, boolean value) Sets abooleanproperty value with the specified name into the message.voidsetByteProperty(String name, byte value) Sets abyteproperty value with the specified name into the message.voidsetDoubleProperty(String name, double value) Sets adoubleproperty value with the specified name into the message.voidsetFloatProperty(String name, float value) Sets afloatproperty value with the specified name into the message.voidsetIntProperty(String name, int value) Sets aintproperty value with the specified name into the message.voidsetJMSCorrelationID(String correlationID) voidsetJMSCorrelationIDAsBytes(byte[] correlationID) voidsetJMSDeliveryMode(int deliveryMode) voidsetJMSDeliveryTime(long deliveryTime) voidsetJMSDestination(jakarta.jms.Destination destination) Sets the Destination object for this message.voidsetJMSExpiration(long expiration) voidSets the message ID.voidsetJMSPriority(int priority) voidsetJMSRedelivered(boolean redelivered) voidsetJMSReplyTo(jakarta.jms.Destination replyTo) voidsetJMSTimestamp(long timestamp) voidsetJMSType(String type) voidsetLongProperty(String name, long value) Sets alongproperty value with the specified name into the message.voidsetObjectProperty(String name, Object value) Sets a Java object property value with the specified name into the message.voidsetSequenceNumber(String sequenceNumber) This method sets the JMS_SQS_SEQUENCE_NUMBER property on the message.voidsetShortProperty(String name, short value) Sets ashortproperty value with the specified name into the message.voidsetSQSMessageId(String sqsMessageID) Set SQS Message Id, used on send.voidsetStringProperty(String name, String value) Sets aStringproperty 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:
getJMSMessageIDin 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:
setJMSMessageIDin interfacejakarta.jms.Message- Parameters:
id- The ID of the message.- Throws:
jakarta.jms.JMSException
-
getJMSTimestamp
public long getJMSTimestamp() throws jakarta.jms.JMSException- Specified by:
getJMSTimestampin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSTimestamp
public void setJMSTimestamp(long timestamp) throws jakarta.jms.JMSException - Specified by:
setJMSTimestampin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSCorrelationIDAsBytes
public byte[] getJMSCorrelationIDAsBytes() throws jakarta.jms.JMSException- Specified by:
getJMSCorrelationIDAsBytesin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSCorrelationIDAsBytes
public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws jakarta.jms.JMSException - Specified by:
setJMSCorrelationIDAsBytesin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSCorrelationID
- Specified by:
setJMSCorrelationIDin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSCorrelationID
- Specified by:
getJMSCorrelationIDin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSReplyTo
public jakarta.jms.Destination getJMSReplyTo() throws jakarta.jms.JMSException- Specified by:
getJMSReplyToin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSReplyTo
public void setJMSReplyTo(jakarta.jms.Destination replyTo) throws jakarta.jms.JMSException - Specified by:
setJMSReplyToin 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:
getJMSDestinationin 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:
setJMSDestinationin interfacejakarta.jms.Message- Parameters:
destination- The destination for this message.- Throws:
jakarta.jms.JMSException
-
getJMSDeliveryMode
public int getJMSDeliveryMode() throws jakarta.jms.JMSException- Specified by:
getJMSDeliveryModein interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSDeliveryMode
public void setJMSDeliveryMode(int deliveryMode) throws jakarta.jms.JMSException - Specified by:
setJMSDeliveryModein interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSRedelivered
public boolean getJMSRedelivered() throws jakarta.jms.JMSException- Specified by:
getJMSRedeliveredin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSRedelivered
public void setJMSRedelivered(boolean redelivered) throws jakarta.jms.JMSException - Specified by:
setJMSRedeliveredin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSType
- Specified by:
getJMSTypein interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSType
- Specified by:
setJMSTypein interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSExpiration
public long getJMSExpiration() throws jakarta.jms.JMSException- Specified by:
getJMSExpirationin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSExpiration
public void setJMSExpiration(long expiration) throws jakarta.jms.JMSException - Specified by:
setJMSExpirationin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSDeliveryTime
public long getJMSDeliveryTime() throws jakarta.jms.JMSException- Specified by:
getJMSDeliveryTimein interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSDeliveryTime
public void setJMSDeliveryTime(long deliveryTime) throws jakarta.jms.JMSException - Specified by:
setJMSDeliveryTimein interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
getJMSPriority
public int getJMSPriority() throws jakarta.jms.JMSException- Specified by:
getJMSPriorityin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
setJMSPriority
public void setJMSPriority(int priority) throws jakarta.jms.JMSException - Specified by:
setJMSPriorityin 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:
clearPropertiesin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
propertyExists
Indicates whether a property value exists for the given property name.- Specified by:
propertyExistsin 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 thebooleanproperty with the specified name.- Specified by:
getBooleanPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
booleanproperty 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 thebyteproperty with the specified name.- Specified by:
getBytePropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
byteproperty 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 theshortproperty with the specified name.- Specified by:
getShortPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
shortproperty 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 theintproperty with the specified name.- Specified by:
getIntPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
intproperty 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 thelongproperty with the specified name.- Specified by:
getLongPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
longproperty 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 thefloatproperty with the specified name.- Specified by:
getFloatPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
floatproperty 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 thedoubleproperty with the specified name.- Specified by:
getDoublePropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
doubleproperty 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 theStringproperty with the specified name.- Specified by:
getStringPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to get.- Returns:
- the
Stringproperty 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
setObjectPropertymethod call, or its equivalent primitive setter method.- Specified by:
getObjectPropertyin 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, anIntegeris 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:
JMSMessagePropertyValuewith object value and corresponding SQS message attribute type and message attribute string value.- Throws:
jakarta.jms.JMSException- On internal error.
-
getPropertyNames
Returns anEnumerationof all the property names.Note that JMS standard header fields are not considered properties and are not returned in this enumeration.
- Specified by:
getPropertyNamesin interfacejakarta.jms.Message- Returns:
- an enumeration of all the names of property values.
- Throws:
jakarta.jms.JMSException- On internal error.
-
setBooleanProperty
Sets abooleanproperty value with the specified name into the message.- Specified by:
setBooleanPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Thebooleanvalue 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 abyteproperty value with the specified name into the message.- Specified by:
setBytePropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Thebytevalue 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 ashortproperty value with the specified name into the message.- Specified by:
setShortPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Theshortvalue 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 aintproperty value with the specified name into the message.- Specified by:
setIntPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Theintvalue 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 alongproperty value with the specified name into the message.- Specified by:
setLongPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Thelongvalue 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 afloatproperty value with the specified name into the message.- Specified by:
setFloatPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Thefloatvalue 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 adoubleproperty value with the specified name into the message.- Specified by:
setDoublePropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- Thedoublevalue 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 aStringproperty value with the specified name into the message.- Specified by:
setStringPropertyin interfacejakarta.jms.Message- Parameters:
name- The name of the property to set.value- TheStringvalue 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:
setObjectPropertyin 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:
acknowledgein 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:
clearBodyin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException- If directly called
-
getBody
- Specified by:
getBodyin interfacejakarta.jms.Message- Throws:
jakarta.jms.JMSException
-
isBodyAssignableTo
- Specified by:
isBodyAssignableToin 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
-