amqpy.proto module

High-level representations of AMQP protocol objects

class amqpy.proto.Frame[source]

Bases: object

AMQP frame

A Frame represents the lowest-level packet of data specified by the AMQP 0.9.1 wire-level protocol. All methods and messages are packed into one or more frames before being sent to the peer.

The format of the AMQP frame is as follows:

offset:         0      1         3         7                 size+7      size+8
                +------+---------+---------+-------------------+-----------+
                | type | channel |  size   |  --- payload ---  | frame-end |
                +------+---------+---------+-------------------+-----------+
size (bytes)        1       2         4             size             1
channel

@property

Get frame channel number

Returns:channel number
Return type:int
data

raw frame data; can be manually manipulated at any time

Type:bytearray
frame_type

@property

Get frame type

Returns:frame type
Return type:int
payload

@property

Get frame payload

Returns:payload
Return type:bytearray
payload_size

@property

Get frame payload size

Returns:payload size
Return type:int
__init__(frame_type=None, channel=0, payload=b'')[source]

Create new Frame

Leave all three parameters as default to create an empty frame whose data can be manually written to afterwards.

Parameters:
  • frame_type (int) – frame type
  • channel (int) – associated channel number
  • payload (bytes or bytearray) – frame payload
class amqpy.proto.Method[source]

Bases: object

AMQP method

The AMQP 0.9.1 protocol specifies communication as sending and receiving “methods”. Methods consist of a “class-id” and “method-id” and are represented by a method_t namedtuple in amqpy. Methods are packed into the payload of a FrameType.METHOD frame, and most methods can be fully sent in a single frame. If the method specified to be carrying content (such as a message), the method frame is followed by additional frames: a FrameType.HEADER frame, then zero or more FrameType.BODY frames.

The format of the FrameType.METHOD frame’s payload is as follows:

offset:         0          2           4
                +----------+-----------+-------------- - -
                | class-id | method-id | arguments...
                +----------+-----------+-------------- - -
size (bytes):         2          2         variable

The format of the FrameType.HEADER frame’s payload is as follows:

offset:         0          2        4           12               14
                +----------+--------+-----------+----------------+------------------- - -
                | class-id | weight | body size | property flags | property list...
                +----------+--------+-----------+----------------+------------------- - -
size (bytes):         2         2         8              2           variable

The format of the FrameType.BODY frame’s payload is simply raw binary data of the message body.

channel_id
Type:int
complete

@property

Check if the message that is carried by this method has been completely assembled, i.e. the expected number of bytes have been loaded

This method is intended to be called when constructing a Method from incoming data.

Returns:True if method is complete, else False
Return type:bool
content
Type:Message or None
method_type
Type:amqpy.spec.method_t
__init__(method_type=None, args=None, content=None, channel_id=None)[source]
Parameters:
  • method_type (method_t) – method type
  • args (AMQPReader or AMQPWriter or None) – method args
  • content (Message or None) – content
  • channel_id (int or None) – the associated channel ID, if any
dump_body_frame(chunk_size) → generator[amqpy.proto.Frame][source]

Create a body frame

This method is intended to be called when sending frames for an already-completed Method.

Parameters:chunk_size (int) – body chunk size in bytes; this is typically the maximum frame size - 8
Returns:generator of FrameType.BODY frames
Return type:generator[amqpy.proto.Frame]
dump_header_frame() → amqpy.proto.Frame[source]

Create a header frame

This method is intended to be called when sending frames for an already-completed Method.

Returns:FrameType.HEADER frame
Return type:amqpy.proto.Frame
dump_method_frame() → amqpy.proto.Frame[source]

Create a method frame

This method is intended to be called when sending frames for an already-completed Method.

Returns:FrameType.METHOD frame
Return type:amqpy.proto.Frame
load_body_frame(frame) → None[source]

Add content to partial method

This method is intended to be called when constructing a Method from incoming data.

Parameters:frame (amqpy.proto.Frame) – FrameType.BODY frame
load_header_frame(frame) → None[source]

Add header to partial method

This method is intended to be called when constructing a Method from incoming data.

Parameters:frame (amqpy.proto.Frame) – FrameType.HEADER frame
load_method_frame(frame) → None[source]

Load method frame payload data

This method is intended to be called when constructing a Method from incoming data.

After calling, self.method_type, self.args, and self.channel_id will be loaded with data from the frame.

Parameters:frame (amqpy.proto.Frame) – FrameType.METHOD frame