Tornado Connection Adapter¶
Use pika with the Tornado IOLoop
Be sure to check out the asynchronous examples including the Tornado specific consumer example.
-
class
pika.adapters.tornado_connection.
TornadoConnection
(parameters=None, on_open_callback=None, on_open_error_callback=None, on_close_callback=None, stop_ioloop_on_close=False, custom_ioloop=None)¶ The TornadoConnection runs on the Tornado IOLoop. If you’re running the connection in a web app, make sure you set stop_ioloop_on_close to False, which is the default behavior for this adapter, otherwise the web app will stop taking requests.
Parameters: - parameters (pika.connection.Parameters) – Connection parameters
- on_open_callback (method) – The method to call when the connection is open
- on_open_error_callback (method) – Method to call if the connection cant be opened
- stop_ioloop_on_close (bool) – Call ioloop.stop() if disconnected
- custom_ioloop – Override using the global IOLoop in Tornado
-
add_backpressure_callback
(callback_method)¶ Call method “callback” when pika believes backpressure is being applied.
Parameters: callback_method (method) – The method to call
-
add_on_close_callback
(callback_method)¶ Add a callback notification when the connection has closed. The callback will be passed the connection, the reply_code (int) and the reply_text (str), if sent by the remote server.
Parameters: callback_method (method) – Callback to call on close
-
add_on_connection_blocked_callback
(callback_method)¶ Add a callback to be notified when RabbitMQ has sent a
Connection.Blocked
frame indicating that RabbitMQ is low on resources. Publishers can use this to voluntarily suspend publishing, instead of relying on back pressure throttling. The callback will be passed theConnection.Blocked
method frame.Parameters: callback_method (method) – Callback to call on Connection.Blocked
-
add_on_connection_unblocked_callback
(callback_method)¶ Add a callback to be notified when RabbitMQ has sent a
Connection.Unblocked
frame letting publishers know it’s ok to start publishing again. The callback will be passed theConnection.Unblocked
method frame.Parameters: callback_method (method) – Callback to call on Connection.Unblocked
-
add_on_open_callback
(callback_method)¶ Add a callback notification when the connection has opened.
Parameters: callback_method (method) – Callback to call when open
-
add_on_open_error_callback
(callback_method, remove_default=True)¶ Add a callback notification when the connection can not be opened.
The callback method should accept the connection object that could not connect, and an optional error message.
Parameters: - callback_method (method) – Callback to call when can’t connect
- remove_default (bool) – Remove default exception raising callback
-
add_timeout
(deadline, callback_method)¶ Add the callback_method to the IOLoop timer to fire after deadline seconds. Returns a handle to the timeout. Do not confuse with Tornado’s timeout where you pass in the time you want to have your callback called. Only pass in the seconds until it’s to be called.
Parameters: - deadline (int) – The number of seconds to wait to call callback
- callback_method (method) – The callback method
Return type:
-
channel
(on_open_callback, channel_number=None)¶ Create a new channel with the next available channel number or pass in a channel number to use. Must be non-zero if you would like to specify but it is recommended that you let Pika manage the channel numbers.
Parameters: - on_open_callback (method) – The callback when the channel is opened
- channel_number (int) – The channel number to use, defaults to the next available.
Return type:
-
close
(reply_code=200, reply_text='Normal shutdown')¶ Disconnect from RabbitMQ. If there are any open channels, it will attempt to close them prior to fully disconnecting. Channels which have active consumers will attempt to send a Basic.Cancel to RabbitMQ to cleanly stop the delivery of messages prior to closing the channel.
Parameters:
-
connect
()¶ Invoke if trying to reconnect to a RabbitMQ server. Constructing the Connection object should connect on its own.
-
consumer_cancel_notify
¶ Specifies if the server supports consumer cancel notification on the active connection.
Return type: bool
-
exchange_exchange_bindings
¶ Specifies if the active connection supports exchange to exchange bindings.
Return type: bool
-
is_closed
¶ Returns a boolean reporting the current connection state.
-
is_closing
¶ Returns a boolean reporting the current connection state.
-
is_open
¶ Returns a boolean reporting the current connection state.
-
publisher_confirms
¶ Specifies if the active connection can use publisher confirmations.
Return type: bool