Delen via


ServiceBusReceivedMessage Class

  • java.lang.Object
    • com.azure.messaging.servicebus.ServiceBusReceivedMessage

public final class ServiceBusReceivedMessage

The data structure encapsulating the message received from Service Bus. The message structure is discussed in detail in the product documentation.

Method Summary

Modifier and Type Method and Description
Map<String,Object> getApplicationProperties()

Gets the set of free-form ServiceBusReceivedMessage properties which may be used for passing metadata associated with the ServiceBusReceivedMessage during Service Bus operations.

BinaryData getBody()

Gets the payload wrapped by the ServiceBusReceivedMessage.

String getContentType()

Gets the content type of the message.

String getCorrelationId()

Gets a correlation identifier.

String getDeadLetterErrorDescription()

Gets the description for a message that has been dead-lettered.

String getDeadLetterReason()

Gets the reason a message was dead-lettered.

String getDeadLetterSource()

Gets the name of the queue or subscription that this message was enqueued on, before it was dead-lettered.

long getDeliveryCount()

Gets the number of the times this message was delivered to clients.

long getEnqueuedSequenceNumber()

Gets the enqueued sequence number assigned to a message by Service Bus.

OffsetDateTime getEnqueuedTime()

Gets the datetime at which this message was enqueued in Azure Service Bus.

OffsetDateTime getExpiresAt()

Gets the datetime at which this message will expire.

String getLockToken()

Gets the lock token for the current message.

OffsetDateTime getLockedUntil()

Gets the datetime at which the lock of this message expires.

String getMessageId()

Gets the identifier for the message.

String getPartitionKey()

Gets the partition key for sending a message to a partitioned entity.

AmqpAnnotatedMessage getRawAmqpMessage()

The representation of message as defined by AMQP protocol.

String getReplyTo()

Gets the address of an entity to send replies to.

String getReplyToSessionId()

Gets or sets a session identifier augmenting the getReplyTo() address.

OffsetDateTime getScheduledEnqueueTime()

Gets the scheduled enqueue time of this message.

long getSequenceNumber()

Gets the unique number assigned to a message by Service Bus.

String getSessionId()

Gets the session id of the message.

ServiceBusMessageState getState()

Gets the state of the message.

String getSubject()

Gets the subject for the message.

Duration getTimeToLive()

Gets the duration before this message expires.

String getTo()

Gets the "to" address.

Methods inherited from java.lang.Object

Method Details

getApplicationProperties

public Map getApplicationProperties()

Gets the set of free-form ServiceBusReceivedMessage properties which may be used for passing metadata associated with the ServiceBusReceivedMessage during Service Bus operations. A common use-case for properties() is to associate serialization hints for the getBody() as an aid to consumers who wish to deserialize the binary data.

Returns:

Application properties associated with this ServiceBusReceivedMessage.

getBody

public BinaryData getBody()

Gets the payload wrapped by the ServiceBusReceivedMessage.

The BinaryData wraps byte array and is an abstraction over many different ways it can be represented. It provides convenience APIs to serialize/deserialize the object.

If the means for deserializing the raw data is not apparent to consumers, a common technique is to make use of getApplicationProperties() when creating the event, to associate serialization hints as an aid to consumers who wish to deserialize the binary data.

Returns:

Binary data representing the payload.

getContentType

public String getContentType()

Gets the content type of the message.

Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json".

Returns:

The contentType of the ServiceBusReceivedMessage.

getCorrelationId

public String getCorrelationId()

Gets 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.

Returns:

The correlation id of this message.

getDeadLetterErrorDescription

public String getDeadLetterErrorDescription()

Gets the description for a message that has been dead-lettered.

Returns:

The description for a message that has been dead-lettered; null otherwise.

getDeadLetterReason

public String getDeadLetterReason()

Gets the reason a message was dead-lettered.

Returns:

The reason a message was dead-lettered; null otherwise.

getDeadLetterSource

public String getDeadLetterSource()

Gets the name of the queue or subscription that this message was enqueued on, before it was dead-lettered.

This value is only set in messages that have been dead-lettered and subsequently auto-forwarded from the dead-letter queue to another entity.

Returns:

The entity in which the message was dead-lettered; null otherwise.

getDeliveryCount

public long getDeliveryCount()

Gets 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.

Returns:

delivery count of this message.

getEnqueuedSequenceNumber

public long getEnqueuedSequenceNumber()

Gets the enqueued sequence number assigned to a message by Service Bus.

The sequence number is a unique 64-bit integer first assigned to a message as it is accepted at its original point of submission.

Returns:

The enqueued sequence number of this message

getEnqueuedTime

public OffsetDateTime getEnqueuedTime()

Gets the datetime at which this message was enqueued in Azure Service Bus.

The UTC datetime 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.

Returns:

The datetime at which the message was enqueued in Azure Service Bus.

getExpiresAt

public OffsetDateTime getExpiresAt()

Gets the datetime at which this message will expire.

The value is the UTC datetime for when the message is scheduled for removal and will no longer available for retrieval from the entity. Expiry is controlled by the getTimeToLive() property. This property is computed from getEnqueuedTime() plus getTimeToLive().

Returns:

The OffsetDateTime at which this message expires.

getLockToken

public String getLockToken()

Gets the lock token for the current message.

The lock token is a reference to the lock that is being held by the broker in PEEK_LOCK mode. Locks are used to explicitly settle messages as explained in the product documentation. The token can also be used to pin the lock permanently through the Deferral API and take the message out of the regular delivery state flow. This property is read-only.

Returns:

The lock-token for this message. null for messages retrieved via RECEIVE_AND_DELETE mode.

getLockedUntil

public OffsetDateTime getLockedUntil()

Gets the datetime 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 datetime until which the message is held locked in the queue/subscription. When the lock expires, the getDeliveryCount() is incremented and the message is again available for retrieval. This property is read-only.

Returns:

the datetime at which the lock of this message expires if the message is received using PEEK_LOCK mode. Otherwise it returns null.

getMessageId

public String getMessageId()

Gets the identifier for the 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.

Returns:

getPartitionKey

public String getPartitionKey()

Gets 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, the getSessionId() property overrides this value.

Returns:

The partition key of this message.

getRawAmqpMessage

public AmqpAnnotatedMessage getRawAmqpMessage()

The representation of message as defined by AMQP protocol.

Returns:

the AmqpAnnotatedMessage representing AMQP message.

getReplyTo

public String getReplyTo()

Gets 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.

Returns:

ReplyTo property value of this message

getReplyToSessionId

public String getReplyToSessionId()

Gets or sets a session identifier augmenting the getReplyTo() address.

This value augments the ReplyTo information and specifies which SessionId should be set for the reply when sent to the reply entity.

Returns:

ReplyToSessionId property value of this message

getScheduledEnqueueTime

public OffsetDateTime getScheduledEnqueueTime()

Gets 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 datetime; the actual activation time depends on the queue's workload and its state.

Returns:

the datetime at which the message will be enqueued in Azure Service Bus

getSequenceNumber

public long getSequenceNumber()

Gets 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.

Returns:

sequence number of this message

getSessionId

public String getSessionId()

Gets the session id of the message.

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. See Message Sessions.

Returns:

The session id of the ServiceBusReceivedMessage.

getState

public ServiceBusMessageState getState()

Gets the state of the message. The state of the message can be Active, Deferred, or Scheduled. Deferred messages have Deferred state, scheduled messages have Scheduled state, all other messages have Active state.

Returns:

The state of the message.

getSubject

public String getSubject()

Gets the subject for the message.

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".

Returns:

The subject for the message.

getTimeToLive

public Duration getTimeToLive()

Gets the duration before this message expires.

This value is the relative duration after which the message expires, starting from the datetime the message has been accepted and stored by the broker, as captured in getScheduledEnqueueTime(). 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.

Returns:

Time to live duration of this message

getTo

public String getTo()

Gets 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.

Returns:

"To" property value of this message

Applies to