ServiceBusMessage Class

A Service Bus Message.

Inheritance
builtins.object
ServiceBusMessage

Constructor

ServiceBusMessage(body: str | bytes | None, *, application_properties: Dict[str | bytes, int | float | bytes | bool | str | UUID] | None = None, session_id: str | None = None, message_id: str | None = None, scheduled_enqueue_time_utc: datetime | None = None, time_to_live: timedelta | None = None, content_type: str | None = None, correlation_id: str | None = None, subject: str | None = None, partition_key: str | None = None, to: str | None = None, reply_to: str | None = None, reply_to_session_id: str | None = None, **kwargs: Any)

Parameters

Name Description
body
Required

The data to send in a single message.

Keyword-Only Parameters

Name Description
application_properties
Dict[str, Union[int or float or bool or bytes or str or UUID or datetime or None]]

The user defined properties on the message.

session_id

The session identifier of the message for a sessionful entity.

message_id

The id to identify the message.

scheduled_enqueue_time_utc

The utc scheduled enqueue time to the message.

time_to_live

The life duration of a message.

content_type

The content type descriptor.

correlation_id

The correlation identifier.

subject

The application specific subject, sometimes referred to as label.

partition_key

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

to

The to address used for auto_forward chaining scenarios.

reply_to

The address of an entity to send replies to.

reply_to_session_id

The session identifier augmenting the reply_to address.

Examples

Sending a message with additional properties


   message_send = ServiceBusMessage(
       "Hello World!!",
       session_id="MySessionID",
       application_properties={'data': 'custom_data'},
       time_to_live=datetime.timedelta(seconds=30),
       label='MyLabel'
   )

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,

message

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

Returns

Type Description
<xref:uamqp.Message>,
<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

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,

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,