Message

class amqpstorm.Message[source]

RabbitMQ Message.

e.g.

# Message Properties.
properties = {
    'content_type': 'text/plain',
    'expiration': '3600',
    'headers': {'key': 'value'},
}
# Create a new message.
message = Message.create(channel, 'Hello RabbitMQ!', properties)
# Publish the message to a queue called, 'my_queue'.
message.publish('my_queue')
Parameters:
  • channel (Channel) – AMQPStorm Channel

  • body (bytes,str,unicode) – Message payload

  • method (dict) – Message method

  • properties (dict) – Message properties

  • auto_decode (bool) – Auto-decode strings when possible. Does not apply to to_dict, or to_tuple.

__init__(channel: Channel | None, body: bytes | str | None = None, method: dict[str, Any] | None = None, properties: dict[str, Any] | None = None, auto_decode: bool = True) None[source]
static create(channel: Channel, body: bytes | str, properties: dict[str, Any] | None = None) Message[source]

Create a new Message.

Parameters:
  • channel (Channel) – AMQPStorm Channel

  • body (bytes,str,unicode) – Message payload

  • properties (dict) – Message properties

Return type:

Message

property body: bytes | str | None

Return the Message Body.

If auto_decode is enabled, the body will automatically be decoded using decode(‘utf-8’) if possible.

Return type:

bytes,str,unicode

property channel: Channel | None

Return the Channel used by this message.

Return type:

Channel

property method: dict[str, Any] | None

Return the Message Method.

If auto_decode is enabled, all strings will automatically be decoded using decode(‘utf-8’) if possible.

Return type:

dict

property properties: dict[str, Any]

Returns the Message Properties.

If auto_decode is enabled, all strings will automatically be decoded using decode(‘utf-8’) if possible.

Return type:

dict

ack() None[source]

Acknowledge Message.

Raises:
Returns:

nack(requeue: bool = True) None[source]

Negative Acknowledgement.

Raises:
Parameters:

requeue (bool) – Re-queue the message

reject(requeue: bool = True) None[source]

Reject Message.

Raises:
Parameters:

requeue (bool) – Re-queue the message

publish(routing_key: str, exchange: str = '', mandatory: bool = False, immediate: bool = False) bool | None[source]

Publish Message.

Parameters:
  • routing_key (str) – Message routing key

  • exchange (str) – The exchange to publish the message to

  • mandatory (bool) – Requires the message is published

  • immediate (bool) – Request immediate delivery

Raises:
Return type:

bool,None

property app_id: Any | None

Get AMQP Message attribute: app_id.

Returns:

property message_id: Any | None

Get AMQP Message attribute: message_id.

Returns:

property content_encoding: Any | None

Get AMQP Message attribute: content_encoding.

Returns:

property content_type: Any | None

Get AMQP Message attribute: content_type.

Returns:

property correlation_id: Any | None

Get AMQP Message attribute: correlation_id.

Returns:

property delivery_mode: Any | None

Get AMQP Message attribute: delivery_mode.

Returns:

property timestamp: Any | None

Get AMQP Message attribute: timestamp.

Returns:

property priority: Any | None

Get AMQP Message attribute: priority.

Returns:

property reply_to: Any | None

Get AMQP Message attribute: reply_to.

Returns:

property message_type: Any | None

Get AMQP Message attribute: message_type.

Returns:

property expiration: Any | None

Get AMQP Message attribute: expiration.

Returns:

property user_id: Any | None

Get AMQP Message attribute: user_id.

Returns:

property redelivered: bool | None

Indicates if this message may have been delivered before (but not acknowledged).

Return type:

bool,None

property delivery_tag: int | None

Server-assigned delivery tag.

Return type:

int,None

json() Any[source]

Deserialize the message body, if it is JSON.

Returns: