Broker connection and pools.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
A connection to the broker.
Parameters: |
|
---|
Usage
Creating a connection:
>>> conn = BrokerConnection("rabbit.example.com")
The connection is established lazily when needed. If you need the connection to be established, then force it to do so using connect():
>>> conn.connect()
Remember to always close the connection:
>>> conn.release()
Attributes
List of exceptions that may be raised by the connection.
List of exceptions that may be raised by the channel.
The host as a hostname/port pair separated by colon.
The underlying connection object.
Warning
This instance is transport specific, so do not depend on the interface of this object.
Methods
Establish connection to server immediately.
Request a new channel.
Wait for a single event from the server.
Parameters: |
|
---|
Usually used from an event loop.
Close the connection (if open).
Ensure we have a connection to the server.
If not retry establishing the connection with the settings specified.
Parameters: |
|
---|
Ensure operation completes, regardless of any channel/connection errors occuring.
Will retry by establishing the connection, and reapplying the function.
Parameters: |
|
---|
Example
This is an example ensuring a publish operation:
>>> def errback(exc, interval):
... print("Couldn't publish message: %r. Retry in %ds" % (
... exc, interval))
>>> publish = conn.ensure(producer, producer.publish,
... errback=errback, max_retries=3)
>>> publish(message, routing_key)
Get the currently used transport class.
Create a copy of the connection with the same connection settings.
Get connection info.
Pool of connections.
See ConnectionPool.
Parameters: |
|
---|
Example usage:
>>> pool = connection.Pool(2)
>>> c1 = pool.acquire()
>>> c2 = pool.acquire()
>>> c3 = pool.acquire()
>>> c1.release()
>>> c3 = pool.acquire()
Pool of channels.
See ChannelPool.
Parameters: |
|
---|
Example usage:
>>> pool = connection.ChannelPool(2)
>>> c1 = pool.acquire()
>>> c2 = pool.acquire()
>>> c3 = pool.acquire()
>>> c1.release()
>>> c3 = pool.acquire()
Create new SimpleQueue, using a channel from this connection.
If name is a string, a queue and exchange will be automatically created using that name as the name of the queue and exchange, also it will be used as the default routing key.
Parameters: |
|
---|
Create new SimpleQueue using a channel from this connection.
Same as SimpleQueue(), but configured with buffering semantics. The resulting queue and exchange will not be durable, also auto delete is enabled. Messages will be transient (not persistent), and acknowledgements are disabled (no_ack).
See also
The shortcut methods BrokerConnection.Pool() and BrokerConnection.ChannelPool() is the recommended way to instantiate these classes.
Maximum number of simultaneous connections exceeded.
Acquire resource.
Parameters: |
|
---|---|
Raises LimitExceeded: | |
if block is false and the limit has been exceeded. |
Release resource so it can be used by another thread.
The caller is responsible for discarding the object, and to never use the resource again. A new resource must be acquired if so needed.
Maximum number of simultaenous channels exceeded.
Acquire resource.
Parameters: |
|
---|---|
Raises LimitExceeded: | |
if block is false and the limit has been exceeded. |
Release resource so it can be used by another thread.
The caller is responsible for discarding the object, and to never use the resource again. A new resource must be acquired if so needed.