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.object
Message

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

body
<xref:<xref:Any Python data type.>>
default value: None

The data to send in the message.

properties
MessageProperties
default value: None

Properties to add to the message.

application_properties
dict
default value: None

Service specific application properties.

annotations
dict
default value: None

Service specific message annotations. Keys in the dictionary must be types.AMQPSymbol or types.AMQPuLong.

header
MessageHeader
default value: None

The message header.

msg_format
int
default value: None

A custom message format. Default is 0.

message
cMessage
default value: None

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.

settler
callable[MessageResponse]
default value: None

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.

delivery_no
default value: None

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.

encoding
str
default value: UTF-8

The encoding to use for parameters supplied as strings. Default is 'UTF-8'

body_type
<xref:uamqp.MessageBodyType>
default value: None

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.

footer
dict
default value: None

The message footer.

delivery_annotations
dict
default value: None

Service specific delivery annotations.

Variables

on_send_complete
callable[MessageSendResult, Exception]

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()

Return type

Exceptions

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

data
bytes or bytearray
Required

The AMQP wire-encoded bytes to decode.

data
Required

Exceptions

TypeError if the message is being sent rather than received.

encode_message

Encode message to AMQP wire-encoded bytearray.

encode_message()

Return type

Exceptions

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()

Return type

Exceptions

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()

Return type

<xref:generator>

Exceptions

TypeError if the message is being sent rather than received.

get_message

Get the underlying C message from this object.

get_message()

Return type

Exceptions

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()

Return type

int

Exceptions

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

failed
bool
Required

Whether this delivery of this message failed. This does not indicate whether subsequence deliveries of this message would also fail.

deliverable
bool
Required

Whether this message will be deliverable to this client on subsequent deliveries - i.e. whether delivery is retryable.

annotations
dict
default value: None

Annotations to attach to response.

Return type

Exceptions

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

condition
bytes or str
default value: None

The AMQP rejection code. By default this is amqp:internal-error.

description
bytes or str
default value: None

A description/reason to accompany the rejection.

info
dict
default value: None

Information about the error condition.

Return type

Exceptions

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()

Return type

Exceptions

TypeError if the message is being sent rather than received.

Attributes

annotations

application_properties

delivery_annotations

header

properties

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.

Return type