amqpy.message module

Messages for AMQP

class amqpy.message.Message(amqpy.message.GenericContent)[source]

Bases: amqpy.message.GenericContent

A Message for use with the Channel.basic_* methods

application_headers

@property

Get application headers

Returns:application headers
Return type:dict
body

Message body (bytes or str or unicode)

channel

Associated channel, set after receiving a message (amqpy.channel.Channel)

delivery_info

Delivery info, set after receiving a message (dict)

delivery_tag

@property

Get delivery tag

Returns:delivery tag
Return type:int
__init__(body='', channel=None, **properties)[source]

If body is a str, then content_encoding will automatically be set to ‘UTF-8’, unless explicitly specified.

Example:

msg = Message('hello world', content_type='text/plain', application_headers={'foo': 7})
Parameters:
  • body (bytes or str or unicode) – message body
  • channel (amqpy.channel.Channel) – associated channel
  • properties
    • content_type (shortstr): MIME content type
    • content_encoding (shortstr): MIME content encoding
    • application_headers: (table): Message header field table: dict[str, str|int|Decimal|datetime|dict]
    • delivery_mode: (octet): Non-persistent (1) or persistent (2)
    • priority (octet): The message priority, 0 to 9
    • correlation_id (shortstr) The application correlation identifier
    • reply_to (shortstr) The destination to reply to
    • expiration (shortstr): Message expiration specification
    • message_id (shortstr): The application message identifier
    • timestamp (datetime.datetime): The message timestamp
    • type (shortstr): The message type name
    • user_id (shortstr): The creating user id
    • app_id (shortstr): The creating application id
    • cluster_id (shortstr): Intra-cluster routing identifier
ack() → None[source]

Acknowledge message

This is a convenience method which calls self.channel.basic_ack()

reject(requeue) → None[source]

Reject message

This is a convenience method which calls self.channel.basic_reject()

Parameters:requeue (bool) – requeue if True else discard the message