AMQP Connections
amqpy.connection.Connection(amqpy.abstract_channel.AbstractChannel)[source]¶Bases: amqpy.abstract_channel.AbstractChannel
The connection class provides methods for a client to establish a network connection to a server, and for both peers to operate the connection thereafter
connected¶@property
Check if connection is connected
| Returns: | True if connected, else False |
|---|---|
| Return type: | bool |
server_capabilities¶@property
Get server capabilities
These properties are set only after successfully connecting.
| Returns: | server capabilities |
|---|---|
| Return type: | dict |
sock¶@property
Access underlying TCP socket
| Returns: | socket |
|---|---|
| Return type: | socket.socket |
channels = None¶Map of {channel_id: Channel} for all active channels
| Type: | dict[int, Channel] |
|---|
transport = None¶| Type: | amqpy.transport.Transport |
|---|
__init__(host='localhost', port=5672, ssl=None, connect_timeout=None, userid='guest', password='guest', login_method='AMQPLAIN', virtual_host='/', locale='en_US', channel_max=65535, frame_max=131072, heartbeat=0, client_properties=None, on_blocked=None, on_unblocked=None)[source]¶Create a connection to the specified host
If you are using SSL, make sure the correct port number is specified (usually 5671), as the default of 5672 is for non-SSL connections.
| Parameters: |
|
|---|
channel(channel_id=None) → amqpy.channel.Channel[source]¶Create a new channel, or fetch the channel associated with channel_id if specified
| Parameters: | channel_id (int or None) – channel ID number |
|---|---|
| Returns: | Channel |
| Return type: | amqpy.channel.Channel |
close(reply_code=0, reply_text='', method_type=method_t(class_id=0, method_id=0)) → None[source]¶Close connection to the server
This method performs a connection close handshake with the server, then closes the underlying connection.
If this connection close is due to a client error, the client may provide a reply_code, reply_text, and method_type to indicate to the server the reason for closing the connection.
| Parameters: |
|
|---|
connect() → None[source]¶Connect using saved connection parameters
This method does not need to be called explicitly; it is called by the constructor during initialization.
Note: reconnecting invalidates all declarations (channels, queues, consumers, delivery tags, etc.).
drain_events(timeout=None) → None[source]¶Wait for an event on all channels
This method should be called after creating consumers in order to receive delivered messages and execute consumer callbacks.
| Parameters: | timeout (float or None) – maximum allowed time to wait for an event |
|---|---|
| Raises: | amqpy.exceptions.Timeout – if the operation times out |
is_alive() → bool[source]¶Check if connection is alive
This method is the primary way to check if the connection is alive.
Side effects: This method may send a heartbeat as a last resort to check if the connection is alive.
| Returns: | True if connection is alive, else False |
|---|---|
| Return type: | bool |
loop(timeout=None) → None[source]¶Call drain_events() continuously
| Parameters: | timeout (float or None) – maximum allowed time to wait for an event |
|---|