pikachewie.broker – A RabbitMQ broker¶
-
class
pikachewie.broker.
Broker
(nodes=None, connect_options=None)¶ A RabbitMQ broker.
nodes is a two-level
dict
containing the names and network locations of the clustered nodes that comprise the RabbitMQ broker, e.g.:{ 'bunny1': {'host': 'localhost'}, 'bunny2': {'host': 'rabbit.example.com', 'port': 5678} }
Valid netloc parameters are host and port. If not specified, nodes defaults to
{'default': {}}
, which represents a broker consisting of one node named “default” located atlocalhost:5672
.connect_options is a
dict
of keywords arguments to be passed topika.connection.ConnectionParameters
. If not specified, thepika
default connection parameters will be used. For the list of supported keyword arguments and their default values, seepika.connection.ConnectionParameters
.Parameters: - nodes (
dict
) – two-level dict of nodenames and node netloc parameters - connect_options (
dict
) – dict ofpika.connection.ConnectionParameters
keyword arguments
-
connect
(on_open_callback=None, stop_ioloop_on_close=False, connection_attempts=<object object>, on_failure_callback=None, cycle_delay=None, blocking=False)¶ Return a new connection to this broker.
This method connects to each node of the broker in turn, until either a connection is successfully established, or the number of total connection_attempts is reached. The order in which the nodes are tried is random, and potentially different between different calls to
connect()
.If connection_attempts is greater than the number of broker nodes, this method cycles through the list of nodes repeatedly as needed, pausing for cycle_delay seconds between each pass through the node list.
If connection_attempts is not specified, it defaults to the number of broker nodes, so that each node is tried at most once. If connection_attempts is explicitly set to None, there is no limit on the number of connection attempts, and
connect()
blocks until a connection is successfully made.When connection_attempts is reached, the resultant behavior depends on whether an on_failure_callback has been specified. If it is defined, the on_failure_callback is called with a
BrokerConnectionError
as its sole argument, andconnect()
returns None. Otherwise,connect()
raises theBrokerConnectionError
.Parameters: - on_open_callback (callable) – invoked once the AMQP connection is opened. Note: this parameter is ignored if blocking is True.
- stop_ioloop_on_close (
bool
) – whether to stop the IOLoop when the connection is closed (default:True
). Note: this parameter is ignored if blocking is True. - connection_attempts (
int
orNoneType
) – maximum numbers of total connection attempts to make before failing - on_failure_callback (callable) – invoked if the connection attempt fails
- cycle_delay (
float
orNoneType
) – number of seconds to sleep between each cycle through the nodes list - blocking (
bool
) – if True, return apika.BlockingConnection
(default:False
)
Returns: new connection to this broker (or
None
)Return type: pika.adapters.tornado_connection.TornadoConnection
orpika.BlockingConnection
orNoneType
Raises:
- nodes (
-
exception
pikachewie.broker.
BrokerConnectionError
¶ Raised when a new connection cannot be opened to a
Broker
.