Channel is created on an active connection using the
Connection.channel() method. Channels can act as normal Python objects:
conn = rabbitpy.Connection() chan = conn.channel() chan.enable_publisher_confirms() chan.close()
or as a Python context manager (See PEP 0343):
with rabbitpy.Connection() as conn: with conn.channel() as chan: chan.enable_publisher_confirms()
When they are used as a context manager with the with statement, when your code exits the block, the channel will automatically close, issuing a clean shutdown with RabbitMQ via the
Channel.Close RPC request.
You should be aware that if you perform actions on a channel with exchanges, queues, messages or transactions that RabbitMQ does not like, it will close the channel by sending an AMQP
Channel.Close RPC request to your application. Upon receipt of such a request, rabbitpy will raise the appropriate exception referenced in the request.
Channel(channel_id, server_capabilities, events, exception_queue, read_queue, write_queue, maximum_frame_size, write_trigger, connection, blocking_read=False)[source]¶
The Channel object is the communications object used by Exchanges, Messages, Queues, and Transactions. It is created by invoking the
rabbitpy.Connection.channel()method. It can act as a context manager, allowing for quick shorthand use:
with connection.channel(): # Do something
To create a new channel, invoke py:meth:~rabbitpy.connection.Connection.channel()
To improve performance, pass blocking_read to True. Note that doing so prevents
KeyboardInterrupt/CTRL-C from exiting the Python interpreter.
- channel_id (int) – The channel # to use for this instance
- server_capabilities (dict) – Features the server supports
- events (rabbitpy.Events) – Event management object
- exception_queue (queue.Queue) – Exception queue
- read_queue (queue.Queue) – Queue to read pending frames from
- write_queue (queue.Queue) – Queue to write pending AMQP objs to
- maximum_frame_size (int) – The max frame size for msg bodies
- write_trigger (socket) – Write to this socket to break IO waiting
- blocking_read (bool) – Use blocking Queue.get to improve performance
Close the channel, cancelling any active consumers, purging the read queue, while looking to see if a Basic.Nack should be sent, sending it if so.
Turn on Publisher Confirms. If confirms are turned on, the Message.publish command will return a bool indicating if a message has been successfully published.
Set a prefetch count for the channel (or all channels on the same connection).
Set a prefetch size in bytes for the channel (or all channels on the same connection).