Channel¶
A 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.
API Documentation¶
-
class
rabbitpy.
Channel
(channel_id, server_capabilities, events, exception_queue, read_queue, write_queue, maximum_frame_size, write_trigger, 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
-
close
()[source]¶ 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.
-
enable_publisher_confirms
()[source]¶ 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.
-
prefetch_count
(value, all_channels=False)[source]¶ Set a prefetch count for the channel (or all channels on the same connection).
Parameters:
-