Select Connection Adapter

A connection adapter that tries to use the best polling method for the platform pika is running on.

class pika.adapters.select_connection.SelectConnection(parameters=None, on_open_callback=None, on_open_error_callback=None, on_close_callback=None, custom_ioloop=None, internal_connection_workflow=True)[source]

An asynchronous connection adapter that attempts to use the fastest event loop adapter for the given platform.

add_on_close_callback(callback)

Add a callback notification when the connection has closed. The callback will be passed the connection and an exception instance. The exception will either be an instance of exceptions.ConnectionClosed if a fully-open connection was closed by user or broker or exception of another type that describes the cause of connection closure/failure.

Parameters

callback (callable) – Callback to call on close, having the signature: callback(pika.connection.Connection, exception)

add_on_connection_blocked_callback(callback)

RabbitMQ AMQP extension - Add a callback to be notified when the connection gets blocked (Connection.Blocked received from RabbitMQ) due to the broker running low on resources (memory or disk). In this state RabbitMQ suspends processing incoming data until the connection is unblocked, so it’s a good idea for publishers receiving this notification to suspend publishing until the connection becomes unblocked.

See also Connection.add_on_connection_unblocked_callback()

See also ConnectionParameters.blocked_connection_timeout.

Parameters

callback (callable) – Callback to call on Connection.Blocked, having the signature callback(connection, pika.frame.Method), where the method frame’s method member is of type pika.spec.Connection.Blocked

add_on_connection_unblocked_callback(callback)

RabbitMQ AMQP extension - Add a callback to be notified when the connection gets unblocked (Connection.Unblocked frame is received from RabbitMQ) letting publishers know it’s ok to start publishing again.

Parameters

callback (callable) – Callback to call on Connection.Unblocked, having the signature callback(connection, pika.frame.Method), where the method frame’s method member is of type pika.spec.Connection.Unblocked

add_on_open_callback(callback)

Add a callback notification when the connection has opened. The callback will be passed the connection instance as its only arg.

Parameters

callback (callable) – Callback to call when open

add_on_open_error_callback(callback, remove_default=True)

Add a callback notification when the connection can not be opened.

The callback method should accept the connection instance that could not connect, and either a string or an exception as its second arg.

Parameters
  • callback (callable) – Callback to call when can’t connect, having the signature _(Connection, Exception)

  • remove_default (bool) – Remove default exception raising callback

property basic_nack

Specifies if the server supports basic.nack on the active connection.

Return type

bool

channel(channel_number=None, on_open_callback=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
  • channel_number (int) – The channel number to use, defaults to the next available.

  • on_open_callback (callable) – The callback when the channel is opened. The callback will be invoked with the Channel instance as its only argument.

Return type

pika.channel.Channel

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
  • reply_code (int) – The code number for the close

  • reply_text (str) – The text reason for the close

Raises

pika.exceptions.ConnectionWrongStateError – if connection is closed or closing.

property consumer_cancel_notify

Specifies if the server supports consumer cancel notification on the active connection.

Return type

bool

classmethod create_connection(connection_configs, on_done, custom_ioloop=None, workflow=None)[source]

Implement :py:classmethod:`pika.adapters.BaseConnection.create_connection()`.

property exchange_exchange_bindings

Specifies if the active connection supports exchange to exchange bindings.

Return type

bool

property ioloop
Returns

the native I/O loop instance underlying async services selected by user or the default selected by the specialized connection adapter (e.g., Twisted reactor, asyncio.SelectorEventLoop, select_connection.IOLoop, etc.)

Return type

object

property is_closed

Returns a boolean reporting the current connection state.

property is_closing

Returns True if connection is in the process of closing due to client-initiated close request, but closing is not yet complete.

property is_open

Returns a boolean reporting the current connection state.

property publisher_confirms

Specifies if the active connection can use publisher confirmations.

Return type

bool