Package com.microsoft.azure.servicebus
Class Message
- java.lang.Object
-
- com.microsoft.azure.servicebus.Message
-
- All Implemented Interfaces:
IMessage,Serializable
public final class Message extends Object implements Serializable, IMessage
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Message()Creates an empty message with an empty byte array as body.Message(byte[] content)Creates a message from a byte array.Message(byte[] content, String contentType)Creates a message from a byte array.Message(MessageBody body)Creates a message from message body.Message(MessageBody body, String contentType)Creates a message from message body.Message(String content)Creates a message from a string.Message(String messageId, byte[] content, String contentType)Creates a message from a byte array.Message(String messageId, MessageBody body, String contentType)Creates a message from message body.Message(String content, String contentType)Creates a message from a string.Message(String messageId, String content, String contentType)Creates a message from a string.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description IMessagecreateCopy()Creates a shallow copy of this message.byte[]getBody()Deprecated.StringgetContentType()Gets the content type of this message.StringgetCorrelationId()Gets a correlation identifier.StringgetDeadLetterSource()Gets the name of the queue or subscription that this message was enqueued on, before it was deadlettered.longgetDeliveryCount()Gets the number of the times this message was delivered to clients.InstantgetEnqueuedTimeUtc()Gets the instant at which this message was enqueued in Azure Service Bus.InstantgetExpiresAtUtc()Gets the instant at which this message will expire.StringgetLabel()Gets the application specific message label.InstantgetLockedUntilUtc()Gets the instant at which the lock of this message expires.UUIDgetLockToken()Gets the lock token for the current message.MessageBodygetMessageBody()Gets the body of this message.StringgetMessageId()Gets the Id of this message.StringgetPartitionKey()Gets the partition key for sending a message to a partitioned entity.Map<String,Object>getProperties()Gets the map of user application properties of this message.StringgetReplyTo()Gets the address of an entity to send replies to.StringgetReplyToSessionId()Gets or sets a session identifier augmenting theReplyToaddress.InstantgetScheduledEnqueuedTimeUtc()Deprecated.InstantgetScheduledEnqueueTimeUtc()Gets the scheduled enqueue time of this message.longgetSequenceNumber()Gets the unique number assigned to a message by Service Bus.StringgetSessionId()Gets the session identifier for a session-aware entity.DurationgetTimeToLive()Gets the duration before this message expires.StringgetTo()Gets the "to" address.StringgetViaPartitionKey()Gets the partition key for sending a message to a entity via another partitioned transfer entity.voidsetBody(byte[] body)Deprecated.voidsetContentType(String contentType)Sets the content type of this message.voidsetCorrelationId(String correlationId)Sets a correlation identifier.voidsetLabel(String label)Sets an application specific message label.voidsetLockedUntilUtc(Instant lockedUntilUtc)voidsetMessageBody(MessageBody body)Sets the body of this message.voidsetMessageId(String messageId)Sets the Id of this message.voidsetPartitionKey(String partitionKey)Sets a partition key for sending a message to a partitioned entityvoidsetProperties(Map<String,Object> properties)Sets the map of user application properties of this message.voidsetReplyTo(String replyTo)Sets the address of an entity to send replies to.voidsetReplyToSessionId(String replyToSessionId)Gets or sets a session identifier augmenting theReplyToaddress.voidsetScheduledEnqueuedTimeUtc(Instant scheduledEnqueueTimeUtc)Deprecated.voidsetScheduledEnqueueTimeUtc(Instant scheduledEnqueueTimeUtc)Sets the scheduled enqueue time of this message.voidsetSessionId(String sessionId)Sets the session identifier for a session-aware entity.voidsetTimeToLive(Duration timeToLive)Sets the duration of time before this message expires.voidsetTo(String to)Sets the "to" address.voidsetViaPartitionKey(String partitionKey)Sets a via-partition key for sending a message to a destination entity via another partitioned entity
-
-
-
Constructor Detail
-
Message
public Message()
Creates an empty message with an empty byte array as body.
-
Message
public Message(String content)
Creates a message from a string. For backward compatibility reasons, the string is converted to a byte array and message body type is set to binary.- Parameters:
content- content of the message.
-
Message
public Message(byte[] content)
Creates a message from a byte array. Message body type is set to binary.- Parameters:
content- content of the message
-
Message
public Message(MessageBody body)
Creates a message from message body.- Parameters:
body- message body
-
Message
public Message(String content, String contentType)
Creates a message from a string. For backward compatibility reasons, the string is converted to a byte array and message body type is set to binary.- Parameters:
content- content of the messagecontentType- content type of the message
-
Message
public Message(byte[] content, String contentType)Creates a message from a byte array. Message body type is set to binary.- Parameters:
content- content of the messagecontentType- content type of the message
-
Message
public Message(MessageBody body, String contentType)
Creates a message from message body.- Parameters:
body- message bodycontentType- content type of the message
-
Message
public Message(String messageId, String content, String contentType)
Creates a message from a string. For backward compatibility reasons, the string is converted to a byte array and message body type is set to binary.- Parameters:
messageId- id of the messagecontent- content of the messagecontentType- content type of the message
-
Message
public Message(String messageId, byte[] content, String contentType)
Creates a message from a byte array. Message body type is set to binary.- Parameters:
messageId- id of the messagecontent- content of the messagecontentType- content type of the message
-
Message
public Message(String messageId, MessageBody body, String contentType)
Creates a message from message body.- Parameters:
messageId- id of the messagebody- message bodycontentType- content type of the message
-
-
Method Detail
-
getDeliveryCount
public long getDeliveryCount()
Description copied from interface:IMessageGets the number of the times this message was delivered to clients. The count is incremented when a message lock expires, or the message is explicitly abandoned by the receiver. This property is read-only.- Specified by:
getDeliveryCountin interfaceIMessage- Returns:
- delivery count of this message.
- See Also:
- Message transfers, locks, and settlement.
-
getMessageId
public String getMessageId()
Description copied from interface:IMessageGets the Id of this message. The message identifier is an application-defined value that uniquely identifies the message and its payload. The identifier is a free-form string and can reflect a GUID or an identifier derived from the application context. If enabled, the duplicate detection feature identifies and removes second and further submissions of messages with the same MessageId.- Specified by:
getMessageIdin interfaceIMessage- Returns:
- Id of this message
-
setMessageId
public void setMessageId(String messageId)
Description copied from interface:IMessageSets the Id of this message.- Specified by:
setMessageIdin interfaceIMessage- Parameters:
messageId- Id of this message- See Also:
IMessage.getMessageId()
-
getTimeToLive
public Duration getTimeToLive()
Description copied from interface:IMessageGets the duration before this message expires. This value is the relative duration after which the message expires, starting from the instant the message has been accepted and stored by the broker, as captured ingetEnqueuedTimeUtc. When not set explicitly, the assumed value is the DefaultTimeToLive set for the respective queue or topic. A message-level TimeToLive value cannot be longer than the entity's DefaultTimeToLive setting and it is silently adjusted if it does.- Specified by:
getTimeToLivein interfaceIMessage- Returns:
- Time to Live duration of this message
- See Also:
- Message Expiration
-
setTimeToLive
public void setTimeToLive(Duration timeToLive)
Description copied from interface:IMessageSets the duration of time before this message expires.- Specified by:
setTimeToLivein interfaceIMessage- Parameters:
timeToLive- Time to Live duration of this message- See Also:
IMessage.getTimeToLive()
-
getContentType
public String getContentType()
Description copied from interface:IMessageGets the content type of this message. Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json". Note that content type is not same as message body type.- Specified by:
getContentTypein interfaceIMessage- Returns:
- content type of this message
-
setContentType
public void setContentType(String contentType)
Description copied from interface:IMessageSets the content type of this message.- Specified by:
setContentTypein interfaceIMessage- Parameters:
contentType- content type of this message- See Also:
IMessage.getContentType()
-
getExpiresAtUtc
public Instant getExpiresAtUtc()
Description copied from interface:IMessageGets the instant at which this message will expire. The value is the UTC instant for when the message is scheduled for removal and will no longer available for retrieval from the entity due to expiration. Expiry is controlled by theTimeToLiveproperty. This property is computed fromEnqueuedTimeUtc+TimeToLive.- Specified by:
getExpiresAtUtcin interfaceIMessage- Returns:
- instant at which this message expires
- See Also:
- Message Expiration
-
getLockedUntilUtc
public Instant getLockedUntilUtc()
Description copied from interface:IMessageGets the instant at which the lock of this message expires. For messages retrieved under a lock (peek-lock receive mode, not pre-settled) this property reflects the UTC instant until which the message is held locked in the queue/subscription. When the lock expires, theDeliveryCountis incremented and the message is again available for retrieval. This property is read-only.- Specified by:
getLockedUntilUtcin interfaceIMessage- Returns:
- the instant at which the lock of this message expires if the message is received using PEEKLOCK mode. Otherwise it returns null.
- See Also:
- Message transfers, locks, and settlement
-
setLockedUntilUtc
public void setLockedUntilUtc(Instant lockedUntilUtc)
-
getEnqueuedTimeUtc
public Instant getEnqueuedTimeUtc()
Description copied from interface:IMessageGets the instant at which this message was enqueued in Azure Service Bus. The UTC instant at which the message has been accepted and stored in the entity. For scheduled messages, this reflects the time when the message was activated. This value can be used as an authoritative and neutral arrival time indicator when the receiver does not want to trust the sender's clock. This property is read-only.- Specified by:
getEnqueuedTimeUtcin interfaceIMessage- Returns:
- the instant at which the message was enqueued in Azure Service Bus
- See Also:
- Message Sequencing and Timestamps
-
getSequenceNumber
public long getSequenceNumber()
Description copied from interface:IMessageGets the unique number assigned to a message by Service Bus. The sequence number is a unique 64-bit integer assigned to a message as it is accepted and stored by the broker and functions as its true identifier. For partitioned entities, the topmost 16 bits reflect the partition identifier. Sequence numbers monotonically increase and are gapless. They roll over to 0 when the 48-64 bit range is exhausted. This property is read-only.- Specified by:
getSequenceNumberin interfaceIMessage- Returns:
- sequence number of this message
- See Also:
- Message Sequencing and Timestamps
-
getSessionId
public String getSessionId()
Description copied from interface:IMessageGets the session identifier for a session-aware entity. For session-aware entities, this application-defined value specifies the session affiliation of the message. Messages with the same session identifier are subject to summary locking and enable exact in-order processing and demultiplexing. For session-unaware entities, this value is ignored.- Specified by:
getSessionIdin interfaceIMessage- Returns:
- session id of this message
- See Also:
- Message Sessions
-
setSessionId
public void setSessionId(String sessionId)
Description copied from interface:IMessageSets the session identifier for a session-aware entity.- Specified by:
setSessionIdin interfaceIMessage- Parameters:
sessionId- session id of this message- See Also:
IMessage.getSessionId()
-
getProperties
public Map<String,Object> getProperties()
Description copied from interface:IMessageGets the map of user application properties of this message. Client applications can set user properties (headers) on the message using this map.- Specified by:
getPropertiesin interfaceIMessage- Returns:
- the map of user application properties of this message
- See Also:
- Messages, payloads, and serialization
-
setProperties
public void setProperties(Map<String,Object> properties)
Description copied from interface:IMessageSets the map of user application properties of this message. Client applications can set user properties on the message using this map.- Specified by:
setPropertiesin interfaceIMessage- Parameters:
properties- the map of user application properties of this message- See Also:
IMessage.getProperties()
-
getCorrelationId
public String getCorrelationId()
Description copied from interface:IMessageGets a correlation identifier. Allows an application to specify a context for the message for the purposes of correlation, for example reflecting the MessageId of a message that is being replied to.- Specified by:
getCorrelationIdin interfaceIMessage- Returns:
- correlation Id of this message
- See Also:
- Message Routing and Correlation
-
setCorrelationId
public void setCorrelationId(String correlationId)
Description copied from interface:IMessageSets a correlation identifier.- Specified by:
setCorrelationIdin interfaceIMessage- Parameters:
correlationId- correlation Id of this message- See Also:
IMessage.getCorrelationId()
-
setTo
public void setTo(String to)
Description copied from interface:IMessageSets the "to" address. This property is reserved for future use in routing scenarios and presently ignored by the broker itself. Applications can use this value in rule-driven auto-forward chaining scenarios to indicate the intended logical destination of the message.
-
getReplyTo
public String getReplyTo()
Description copied from interface:IMessageGets the address of an entity to send replies to. This optional and application-defined value is a standard way to express a reply path to the receiver of the message. When a sender expects a reply, it sets the value to the absolute or relative path of the queue or topic it expects the reply to be sent to.- Specified by:
getReplyToin interfaceIMessage- Returns:
- ReplyTo property value of this message
- See Also:
- Message Routing and Correlation
-
setReplyTo
public void setReplyTo(String replyTo)
Description copied from interface:IMessageSets the address of an entity to send replies to.- Specified by:
setReplyToin interfaceIMessage- Parameters:
replyTo- ReplyTo property value of this message- See Also:
IMessage.getReplyTo()
-
getLabel
public String getLabel()
Description copied from interface:IMessageGets the application specific message label. This property enables the application to indicate the purpose of the message to the receiver in a standardized fashion, similar to an email subject line. The mapped AMQP property is "subject".
-
setLabel
public void setLabel(String label)
Description copied from interface:IMessageSets an application specific message label.- Specified by:
setLabelin interfaceIMessage- Parameters:
label- Label property value of this message- See Also:
IMessage.getLabel()
-
getReplyToSessionId
public String getReplyToSessionId()
Description copied from interface:IMessageGets or sets a session identifier augmenting theReplyToaddress. This value augments the ReplyTo information and specifies which SessionId should be set for the reply when sent to the reply entity.- Specified by:
getReplyToSessionIdin interfaceIMessage- Returns:
- ReplyToSessionId property value of this message
- See Also:
- Message Routing and Correlation
-
setReplyToSessionId
public void setReplyToSessionId(String replyToSessionId)
Description copied from interface:IMessageGets or sets a session identifier augmenting theReplyToaddress.- Specified by:
setReplyToSessionIdin interfaceIMessage- Parameters:
replyToSessionId- ReplyToSessionId property value of this message
-
getScheduledEnqueuedTimeUtc
@Deprecated public Instant getScheduledEnqueuedTimeUtc()
Deprecated.Description copied from interface:IMessageGets the scheduled enqueue time of this message. This value is used for delayed message availability. The message is safely added to the queue, but is not considered active and therefore not retrievable until the scheduled enqueue time. Mind that the message may not be activated (enqueued) at the exact given instant; the actual activation time depends on the queue's workload and its state.- Specified by:
getScheduledEnqueuedTimeUtcin interfaceIMessage- Returns:
- the instant at which the message will be enqueued in Azure Service Bus
- See Also:
- Message Sequencing and Timestamps
-
setScheduledEnqueuedTimeUtc
@Deprecated public void setScheduledEnqueuedTimeUtc(Instant scheduledEnqueueTimeUtc)
Deprecated.Description copied from interface:IMessageSets the scheduled enqueue time of this message.- Specified by:
setScheduledEnqueuedTimeUtcin interfaceIMessage- Parameters:
scheduledEnqueueTimeUtc- the instant at which this message should be enqueued in Azure Service Bus- See Also:
IMessage.getScheduledEnqueueTimeUtc()
-
getScheduledEnqueueTimeUtc
public Instant getScheduledEnqueueTimeUtc()
Description copied from interface:IMessageGets the scheduled enqueue time of this message. This value is used for delayed message availability. The message is safely added to the queue, but is not considered active and therefore not retrievable until the scheduled enqueue time. Mind that the message may not be activated (enqueued) at the exact given instant; the actual activation time depends on the queue's workload and its state.- Specified by:
getScheduledEnqueueTimeUtcin interfaceIMessage- Returns:
- the instant at which the message will be enqueued in Azure Service Bus
- See Also:
- Message Sequencing and Timestamps
-
setScheduledEnqueueTimeUtc
public void setScheduledEnqueueTimeUtc(Instant scheduledEnqueueTimeUtc)
Description copied from interface:IMessageSets the scheduled enqueue time of this message.- Specified by:
setScheduledEnqueueTimeUtcin interfaceIMessage- Parameters:
scheduledEnqueueTimeUtc- the instant at which this message should be enqueued in Azure Service Bus- See Also:
IMessage.getScheduledEnqueueTimeUtc()
-
getPartitionKey
public String getPartitionKey()
Description copied from interface:IMessageGets the partition key for sending a message to a partitioned entity. For partitioned entities, setting this value enables assigning related messages to the same internal partition, so that submission sequence order is correctly recorded. The partition is chosen by a hash function over this value and cannot be chosen directly. For session-aware entities, theSessionIdproperty overrides this value.- Specified by:
getPartitionKeyin interfaceIMessage- Returns:
- partition key of this message
- See Also:
- Partitioned entities
-
setPartitionKey
public void setPartitionKey(String partitionKey)
Description copied from interface:IMessageSets a partition key for sending a message to a partitioned entity- Specified by:
setPartitionKeyin interfaceIMessage- Parameters:
partitionKey- partition key of this message- See Also:
IMessage.getPartitionKey()
-
getViaPartitionKey
public String getViaPartitionKey()
Description copied from interface:IMessageGets the partition key for sending a message to a entity via another partitioned transfer entity. If a message is sent via a transfer queue in the scope of a transaction, this value selects the transfer queue partition: This is functionally equivalent toIMessage.getPartitionKey()and ensures that messages are kept together and in order as they are transferred.- Specified by:
getViaPartitionKeyin interfaceIMessage- Returns:
- partition key on the via queue.
- See Also:
- Transfers and Send Via
-
setViaPartitionKey
public void setViaPartitionKey(String partitionKey)
Description copied from interface:IMessageSets a via-partition key for sending a message to a destination entity via another partitioned entity- Specified by:
setViaPartitionKeyin interfaceIMessage- Parameters:
partitionKey- via-partition key of this message- See Also:
IMessage.getViaPartitionKey()
-
getDeadLetterSource
public String getDeadLetterSource()
Description copied from interface:IMessageGets the name of the queue or subscription that this message was enqueued on, before it was deadlettered. This value is only set in messages that have been dead-lettered and subsequently auto-forwarded from the dead-letter queue to another entity. Indicates the entity in which the message was dead-lettered. This property is read-only.- Specified by:
getDeadLetterSourcein interfaceIMessage- Returns:
- dead letter source of this message
- See Also:
- Dead-letter queues
-
getLockToken
public UUID getLockToken()
Description copied from interface:IMessageGets the lock token for the current message. The lock token is a reference to the lock that is being held by the broker in PEEKLOCK mode. Locks are used to explicitly settle messages as explained in the product documentation in more detail. The token can also be used to pin the lock permanently through the Deferral API and, with that, take the message out of the regular delivery state flow. This property is read-only.- Specified by:
getLockTokenin interfaceIMessage- Returns:
- lock token of this message.
- See Also:
- Message transfers, locks, and settlement
-
getBody
@Deprecated public byte[] getBody()
Deprecated.Description copied from interface:IMessageGets the body of this message as a byte array. It is up to client applications to decode the bytes.- Specified by:
getBodyin interfaceIMessage- Returns:
- body of this message
- See Also:
- Messages, payloads, and serialization
-
setBody
@Deprecated public void setBody(byte[] body)
Deprecated.Description copied from interface:IMessageSets the body of this message as a byte array.- Specified by:
setBodyin interfaceIMessage- Parameters:
body- body of this message- See Also:
IMessage.getBody()
-
getMessageBody
public MessageBody getMessageBody()
Description copied from interface:IMessageGets the body of this message. Client applications should extract message content based on body type.- Specified by:
getMessageBodyin interfaceIMessage- Returns:
- body of this message
- See Also:
- Messages, payloads, and serialization
-
setMessageBody
public void setMessageBody(MessageBody body)
Description copied from interface:IMessageSets the body of this message.- Specified by:
setMessageBodyin interfaceIMessage- Parameters:
body- body of this message- See Also:
IMessage.getMessageBody()
-
createCopy
public IMessage createCopy()
Description copied from interface:IMessageCreates a shallow copy of this message.- Specified by:
createCopyin interfaceIMessage- Returns:
- copy of this message
-
-