ServiceBusReceivedMessage Class

A Service Bus Message received from service side.

Inheritance
azure.servicebus._common.message.ServiceBusMessage
ServiceBusReceivedMessage

Constructor

ServiceBusReceivedMessage(message: 'Message' | 'pyamqp_Message', receive_mode: ServiceBusReceiveMode | str = ServiceBusReceiveMode.PEEK_LOCK, frame: 'TransferFrame' | None = None, **kwargs: Any)

Parameters

Name Description
message
Required
receive_mode
Default value: ServiceBusReceiveMode.PEEK_LOCK
frame
Default value: None

Examples

Checking the properties on a received message.


       from typing import List
       from azure.servicebus import ServiceBusReceivedMessage
       messages_complex: List[ServiceBusReceivedMessage] = servicebus_receiver.receive_messages(max_wait_time=5)
       for message in messages_complex:
           print("Receiving: {}".format(message))
           print("Time to live: {}".format(message.time_to_live))
           print("Sequence number: {}".format(message.sequence_number))
           print("Enqueued Sequence number: {}".format(message.enqueued_sequence_number))
           print("Partition Key: {}".format(message.partition_key))
           print("Application Properties: {}".format(message.application_properties))
           print("Delivery count: {}".format(message.delivery_count))
           print("Message ID: {}".format(message.message_id))
           print("Locked until: {}".format(message.locked_until_utc))
           print("Lock Token: {}".format(message.lock_token))
           print("Enqueued time: {}".format(message.enqueued_time_utc))

Variables

Name Description
auto_renew_error
<xref:azure.servicebus.AutoLockRenewTimeout> or <xref:azure.servicebus.AutoLockRenewFailed>

Error when AutoLockRenewer is used and it fails to renew the message lock.

Attributes

application_properties

The user defined properties on the message.

Returns

Type Description
bytes, <xref:PrimitiveTypes>],

body

The body of the Message. The format may vary depending on the body type: For DATA, the body could be bytes or Iterable[bytes]. For SEQUENCE, the body could be List or Iterable[List]. For VALUE, the body could be any type.

Returns

Type Description
Any

body_type

The body type of the underlying AMQP message.

Returns

Type Description

content_type

The content type descriptor.

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

Returns

Type Description
str,

correlation_id

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

See Message Routing and Correlation in https://docs.microsoft.com/azure/service-bus-messaging/service-bus-messages-payloads?#message-routing-and-correlation.

Returns

Type Description
str,

dead_letter_error_description

Dead letter error description, when the message is received from a deadletter subqueue of an entity.

Returns

Type Description
str

dead_letter_reason

Dead letter reason, when the message is received from a deadletter subqueue of an entity.

Returns

Type Description
str

dead_letter_source

The name of the queue or subscription that this message was enqueued on, before it was deadlettered. This property 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.

Returns

Type Description
str

delivery_count

Number of deliveries that have been attempted for this message. The count is incremented when a message lock expires or the message is explicitly abandoned by the receiver.

Returns

Type Description
int

enqueued_sequence_number

For messages that have been auto-forwarded, this property reflects the sequence number that had first been assigned to the message at its original point of submission.

Returns

Type Description
int

enqueued_time_utc

The UTC datetime at which the message has been accepted and stored in the entity.

Returns

Type Description

expires_at_utc

The UTC datetime at which the message is marked for removal and no longer available for retrieval from the entity due to expiration. Expiry is controlled by the Message.time_to_live property. This property is computed from Message.enqueued_time_utc + Message.time_to_live.

Returns

Type Description

lock_token

The lock token for the current message serving as a reference to the lock that is being held by the broker in PEEK_LOCK mode.

Returns

Type Description
UUID,
str

locked_until_utc

The UTC datetime until which the message will be locked in the queue/subscription. When the lock expires, delivery count of the message is incremented and the message is again available for retrieval.

Returns

Type Description

message

Get the underlying LegacyMessage. This is deprecated and will be removed in a later release.

Returns

Type Description
<xref:LegacyMessage>

message_id

The id to identify 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 (see https://docs.microsoft.com/azure/service-bus-messaging/duplicate-detection) feature identifies and removes second and further submissions of messages with the same message id.

Returns

Type Description
str,

partition_key

The partition key for sending a message to a partitioned entity.

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.

See Partitioned queues and topics in https://docs.microsoft.com/azure/service-bus-messaging/service-bus-partitioning.

Returns

Type Description
str,

raw_amqp_message

Advanced usage only. The internal AMQP message payload that is sent or received. :rtype: ~azure.servicebus.amqp.AmqpAnnotatedMessage

reply_to

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.

See Message Routing and Correlation in https://docs.microsoft.com/azure/service-bus-messaging/service-bus-messages-payloads?#message-routing-and-correlation.

Returns

Type Description
str,

reply_to_session_id

The session identifier augmenting the reply_to address.

This value augments the reply_to information and specifies which session id should be set for the reply when sent to the reply entity.

See Message Routing and Correlation in https://docs.microsoft.com/azure/service-bus-messaging/service-bus-messages-payloads?#message-routing-and-correlation.

Returns

Type Description
str,

scheduled_enqueue_time_utc

The utc scheduled enqueue time to the message.

This property can be used for scheduling when sending a message through ServiceBusSender.send method. If cancelling scheduled messages is required, you should use the ServiceBusSender.schedule method, which returns sequence numbers that can be used for future cancellation. scheduled_enqueue_time_utc is None if not set.

Returns

Type Description

sequence_number

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. They roll over to 0 when the 48-64 bit range is exhausted.

Returns

Type Description
int

session_id

The session identifier of the message for a sessionful entity.

For sessionful 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 non-sessionful entities, this value is ignored.

See Message Sessions in https://docs.microsoft.com/azure/service-bus-messaging/message-sessions.

Returns

Type Description
str,

state

Defaults to Active. Represents the message state of the message. Can be Active, Deferred. or Scheduled.

Returns

Type Description

subject

The application specific subject, sometimes referred to as a 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.

Returns

Type Description
str

time_to_live

The life duration of a message.

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 in enqueued_time_utc. When not set explicitly, the assumed value is the DefaultTimeToLive for the respective queue or topic. A message-level time-to-live value cannot be longer than the entity's time-to-live setting and it is silently adjusted if it does.

See Expiration in https://docs.microsoft.com/azure/service-bus-messaging/message-expiration

Returns

Type Description

to

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.

See https://docs.microsoft.com/azure/service-bus-messaging/service-bus-auto-forwarding for more details.

Returns

Type Description
str,