Message Class
An AMQP message.
When sending, if body type information is not provided, then depending on the nature of the data, different body encoding will be used. If the data is str or bytes, a single part DataBody will be sent. If the data is a list of str/bytes, a multipart DataBody will be sent. Any other type of list or any other type of data will be sent as a ValueBody. An empty payload will also be sent as a ValueBody. If body type information is provided, then the Message will use the given body type to encode the data or raise error if the data doesn't match the body type.
- Inheritance
-
builtins.objectMessage
Constructor
Message(body=None, properties=None, application_properties=None, annotations=None, header=None, msg_format=None, message=None, settler=None, delivery_no=None, encoding='UTF-8', body_type=None, footer=None, delivery_annotations=None)
Parameters
Name | Description |
---|---|
body
|
<xref:<xref:Any Python data type.>>
The data to send in the message. Default value: None
|
properties
|
Properties to add to the message. Default value: None
|
application_properties
|
Service specific application properties. Default value: None
|
annotations
|
Service specific message annotations. Keys in the dictionary must be types.AMQPSymbol or types.AMQPuLong. Default value: None
|
header
|
The message header. Default value: None
|
msg_format
|
A custom message format. Default is 0. Default value: None
|
message
|
Internal only. This is used to wrap an existing message that has been received from an AMQP service. If specified, all other parameters will be ignored. Default value: None
|
settler
|
Internal only. This is used when wrapping an existing message that has been received from an AMQP service. Should only be specified together with message and is to settle the message. Default value: None
|
delivery_no
|
Internal only. This is used when wrapping an existing message that has been received from an AMQP service. Should only be specified together with message and specifies the messages client delivery number. Default value: None
|
encoding
|
The encoding to use for parameters supplied as strings. Default is 'UTF-8' Default value: UTF-8
|
body_type
|
<xref:uamqp.MessageBodyType>
The AMQP body type used to specify the type of the body section of an amqp message. By default is None which means depending on the nature of the data, different body encoding will be used. If the data is str or bytes, a single part DataBody will be sent. If the data is a list of str/bytes, a multipart DataBody will be sent. Any other type of list or any other type of data will be sent as a ValueBody. An empty payload will also be sent as a ValueBody. Please check class ~uamqp.MessageBodyType for usage information of each body type. Default value: None
|
footer
|
The message footer. Default value: None
|
delivery_annotations
|
Service specific delivery annotations. Default value: None
|
Variables
Name | Description |
---|---|
on_send_complete
|
A custom callback to be run on completion of the send operation of this message. The callback must take two parameters, a result (of type MessageSendResult) and an error (of type Exception). The error parameter may be None if no error ocurred or the error information was undetermined. |
Methods
accept |
Send a response disposition to the service to indicate that a received message has been accepted. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. Returns True is message was accepted, or False if the message was already settled. |
decode_from_bytes |
Decode an AMQP message from a bytearray. The returned message will not have a delivery context and therefore will be considered to be in an "already settled" state. |
encode_message |
Encode message to AMQP wire-encoded bytearray. |
gather |
Return all the messages represented by this object. This will always be a list of a single message. |
get_data |
Get the body data of the message. The format may vary depending on the body type. |
get_message |
Get the underlying C message from this object. |
get_message_encoded_size |
Pre-emptively get the size of the message once it has been encoded to go over the wire so we can raise an error if the message will be rejected for being to large. This method is not available for messages that have been received. |
modify |
Send a response disposition to the service to indicate that a received message has been modified. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. Returns True is message was modified, or False if the message was already settled. |
reject |
Send a response disposition to the service to indicate that a received message has been rejected. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. A rejected message will increment the messages delivery count. Returns True is message was rejected, or False if the message was already settled. |
release |
Send a response disposition to the service to indicate that a received message has been released. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. A released message will not incremenet the messages delivery count. Returns True is message was released, or False if the message was already settled. |
accept
Send a response disposition to the service to indicate that a received message has been accepted. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. Returns True is message was accepted, or False if the message was already settled.
accept()
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
decode_from_bytes
Decode an AMQP message from a bytearray. The returned message will not have a delivery context and therefore will be considered to be in an "already settled" state.
decode_from_bytes(data)
Parameters
Name | Description |
---|---|
data
Required
|
The AMQP wire-encoded bytes to decode. |
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
encode_message
Encode message to AMQP wire-encoded bytearray.
encode_message()
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
gather
Return all the messages represented by this object. This will always be a list of a single message.
gather()
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
get_data
Get the body data of the message. The format may vary depending on the body type.
get_data()
Returns
Type | Description |
---|---|
<xref:generator>
|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
get_message
Get the underlying C message from this object.
get_message()
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
get_message_encoded_size
Pre-emptively get the size of the message once it has been encoded to go over the wire so we can raise an error if the message will be rejected for being to large.
This method is not available for messages that have been received.
get_message_encoded_size()
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
modify
Send a response disposition to the service to indicate that a received message has been modified. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. Returns True is message was modified, or False if the message was already settled.
modify(failed, deliverable, annotations=None)
Parameters
Name | Description |
---|---|
failed
Required
|
Whether this delivery of this message failed. This does not indicate whether subsequence deliveries of this message would also fail. |
deliverable
Required
|
Whether this message will be deliverable to this client on subsequent deliveries - i.e. whether delivery is retryable. |
annotations
|
Annotations to attach to response. Default value: None
|
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
reject
Send a response disposition to the service to indicate that a received message has been rejected. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. A rejected message will increment the messages delivery count. Returns True is message was rejected, or False if the message was already settled.
reject(condition=None, description=None, info=None)
Parameters
Name | Description |
---|---|
condition
|
The AMQP rejection code. By default this is amqp:internal-error. Default value: None
|
description
|
A description/reason to accompany the rejection. Default value: None
|
info
|
Information about the error condition. Default value: None
|
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
release
Send a response disposition to the service to indicate that a received message has been released. If the client is running in PeekLock mode, the service will wait on this disposition. Otherwise it will be ignored. A released message will not incremenet the messages delivery count. Returns True is message was released, or False if the message was already settled.
release()
Returns
Type | Description |
---|---|
Exceptions
Type | Description |
---|---|
TypeError if the message is being sent rather than received.
|
Attributes
annotations
application_properties
data
delivery_annotations
footer
header
message_annotations
properties
sequence
settled
Whether the message transaction for this message has been completed. If this message is to be sent, the message will be settled=True once a disposition has been received from the service. If this message has been received, the message will be settled=True once a disposition has been sent to the service.
Returns
Type | Description |
---|---|
value
Azure SDK for Python