pikachewie.agent – PikaChewie agent classes¶
-
class
pikachewie.agent.
ConsumerAgent
(consumer, broker, bindings, no_ack=False, config=None)¶ A RabbitMQ client that passes Messages between a Broker and a Consumer.
-
acknowledge
(message)¶ Acknowledge delivery of the given message.
Sends a Basic.Ack RPC method with the message’s delivery tag to RabbitMQ.
Parameters: message ( pikachewie.message.Message
) – the message to acknowledge
-
add_on_cancel_callback
()¶ Add an on-cancel callback.
-
add_on_channel_close_callback
()¶ Add an on-channel-close callback.
This method is invoked when the channel is opened.
-
add_on_connection_close_callback
()¶ Add an on-connection-close callback.
This method is invoked when the connection is opened.
-
bind
(queue, exchange, routing_key, method_frame)¶ Declare and bind the given queue to the given exchange.
The queue is bound to the exchange via the given routing_key.
-
bind_queue
(queue, exchange, routing_key, method_frame)¶ Bind the given queue to the given exchange via the given routing_key.
-
connect
()¶ Open a connection to RabbitMQ.
When the connection is established, the on_connection_open method will be invoked by pika.
-
create_binding
(queue, exchange, routing_key)¶ Create a binding using the given queue, exchange, and routing_key.
This method will declare the exchange and queue.
-
create_bindings
()¶ Create a queue binding for each of the Agent’s declared bindings.
-
declare_exchange
(callback, exchange)¶ Declare the given exchange in RabbitMQ.
-
declare_queue
(callback, queue)¶ Declare the given queue in RabbitMQ.
-
disconnect
()¶ Close the connection to RabbitMQ.
-
ensure_consuming
(queue, method_frame)¶ Ensure that this agent is consuming from the given queue.
-
is_consuming_from
(queue)¶ Whether this agent is currently consuming from the given queue.
Return type: bool
-
on_channel_close
(channel, reply_code, reply_text)¶ Callback invoked when the RabbitMQ channel is unexpectedly closed.
Channels are usually closed if you attempt to do something that violates the protocol, such as redeclare an exchange or queue with different paramters. In this case, we’ll close the connection to shutdown the object.
Parameters: method_frame ( pika.frame.Method
) – the Channel.Close method frame
-
on_channel_open
(channel)¶ Callback invoked when a new channel has been opened.
Parameters: channel ( pika.channel.Channel
) – the newly created channel
-
on_connection_close
(connection, reply_code, reply_text)¶ Callback invoked when the RabbitMQ connection is closed unexpectedly.
-
on_connection_failure
(exc)¶ Callback invoked when a RabbitMQ connection cannot be established.
Parameters: exc (exception) – the exception raised
-
on_connection_open
(connection)¶ Callback invoked when a connection to RabbitMQ is established.
Parameters: connection ( pika.adapters.tornado_connection.TornadoConnection
) – the newly opened connection
-
on_consumer_cancel
(method_frame)¶ Callback invoked when RabbitMQ sends a Basic.Cancel for a consumer.
Parameters: method_frame ( pika.frame.Method
) – the Basic.Cancel method frame
-
open_channel
()¶ Open a new channel on the current connection with RabbitMQ.
When RabbitMQ responds that the channel is open, the on_channel_open callback will be invoked.
-
process
(channel, method, header, body)¶ Process a message received from RabbitMQ.
Parameters: - channel (
pika.channel.Channel
) – the channel the message was received on - method (
pika.frame.Method
) – the method frame - header (
pika.frame.Header
) – the header frame - body (str) – the message body
- channel (
-
reconnect
()¶ Reconnect to RabbitMQ.
-
reject
(delivery_tag, requeue=True)¶ Reject the message on the broker and log it.
Parameters:
-
run
()¶ Connect to RabbitMQ and start the connection’s IOLoop.
By starting the IOLoop, this method will block, enabling the connection to operate.
-
start_consuming
(queue)¶ Start consuming messages on the given queue.
-
stop
()¶ Cleanly shutdown the connection to RabbitMQ.
-