ServiceBusMessage Class
A Service Bus Message.
- Inheritance
-
builtins.objectServiceBusMessage
Constructor
ServiceBusMessage(body: Optional[Union[str, bytes]], **kwargs: Any)
Parameters
- application_properties
- <xref:Optional>[dict]
The user defined properties on the message.
- session_id
- <xref:Optional>[str]
The session identifier of the message for a sessionful entity.
- message_id
- <xref:Optional>[str]
The id to identify the message.
- scheduled_enqueue_time_utc
- <xref:Optional>[datetime]
The utc scheduled enqueue time to the message.
- time_to_live
- <xref:Optional>[timedelta]
The life duration of a message.
- content_type
- <xref:Optional>[str]
The content type descriptor.
- correlation_id
- <xref:Optional>[str]
The correlation identifier.
- subject
- <xref:Optional>[str]
The application specific subject, sometimes referred to as label.
- partition_key
- <xref:Optional>[str]
The partition key for sending a message to a partitioned entity.
- to
- <xref:Optional>[str]
The to address used for auto_forward chaining scenarios.
- reply_to
- <xref:Optional>[str]
The address of an entity to send replies to.
- reply_to_session_id
- <xref:Optional>[str]
The session identifier augmenting the reply_to address.
Examples
Sending a message with additional properties
message = ServiceBusMessage(
"Hello World!!",
session_id="MySessionID",
application_properties={'data': 'custom_data'},
time_to_live=datetime.timedelta(seconds=30),
label='MyLabel'
)
Attributes
application_properties
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.
Return type
body_type
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".
Return type
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.
Return type
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.
Return type
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.
Return type
raw_amqp_message
Advanced usage only. The internal AMQP message payload that is sent or received.
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.
Return type
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.
Return type
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.
Return type
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.
Return type
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.
Return type
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
Return type
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.
Return type
Feedback
Submit and view feedback for