Message

class amqpstorm.Message(channel, auto_decode=True, **message)

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

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

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

  • method (dict) – Message method

  • properties (dict) – Message properties

ack()

Acknowledge Message.

Raises
Returns

property app_id

Get AMQP Message attribute: app_id.

Returns

property body

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

Return the Channel used by this message.

Return type

Channel

property content_encoding

Get AMQP Message attribute: content_encoding.

Returns

property content_type

Get AMQP Message attribute: content_type.

Returns

property correlation_id

Get AMQP Message attribute: correlation_id.

Returns

static create(channel, body, properties=None)

Create a new Message.

Parameters
  • channel (Channel) – AMQPStorm Channel

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

  • properties (dict) – Message properties

Return type

Message

property delivery_mode

Get AMQP Message attribute: delivery_mode.

Returns

property delivery_tag

Server-assigned delivery tag.

Return type

int,None

json()

Deserialize the message body, if it is JSON.

Returns

property message_id

Get AMQP Message attribute: message_id.

Returns

property method

Return the Message Method.

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

Return type

dict

nack(requeue=True)

Negative Acknowledgement.

Raises
Parameters

requeue (bool) – Re-queue the message

property priority

Get AMQP Message attribute: priority.

Returns

property properties

Returns the Message Properties.

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

Return type

dict

publish(routing_key, exchange='', mandatory=False, immediate=False)

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 redelivered

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

Return type

bool,None

reject(requeue=True)

Reject Message.

Raises
Parameters

requeue (bool) – Re-queue the message

property reply_to

Get AMQP Message attribute: reply_to.

Returns

property timestamp

Get AMQP Message attribute: timestamp.

Returns