tavrida.amqp_driver package

Submodules

tavrida.amqp_driver.base module

class tavrida.amqp_driver.base.AbstractClient(config)

Bases: object

close_connection()
config
connect()
connection
class tavrida.amqp_driver.base.AbstractReader(config)

Bases: tavrida.amqp_driver.base.AbstractClient

bind_queue(exchange_name, routing_key)
create_queue()
run()
stop()
class tavrida.amqp_driver.base.AbstractWriter(config)

Bases: tavrida.amqp_driver.base.AbstractClient

create_exchange(exchange_name, ex_type)
publish_message(exchange, routing_key, message)
class tavrida.amqp_driver.base.AbstractWriterFactory

Bases: object

get_writer(config)
get_writer_by_reader(reader)

tavrida.amqp_driver.driver module

class tavrida.amqp_driver.driver.AMQPDriver(config)

Bases: object

bind_queue(queue, exchange, service_name)
create_exchange(exchange_name)
create_queue(queue)
create_reader(queue, preprocessor=None)
create_writer()
listen(queue, preprocessor=None)
publish_message(exchange, routing_key, message)
reader
send_heartbeat_via_reader()
writer

tavrida.amqp_driver.pika_async module

class tavrida.amqp_driver.pika_async.BasePikaAsync(config)

Bases: tavrida.amqp_driver.base.AbstractClient

channel
close_channel()

Call to close the channel with RabbitMQ cleanly by issuing the Channel.Close RPC command.

close_connection()

This method closes the connection to RabbitMQ.

connect()

This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter.

Return type:pika.SelectConnection
on_connection_open(unused_connection)

This method is called by pika once the connection to RabbitMQ has been established. It passes the handle to the connection object in case we need it, but in this case, we’ll just mark it unused.

open_channel()

Open a new channel with RabbitMQ by issuing the Channel.Open RPC command. When RabbitMQ responds that the channel is open, the on_channel_open callback will be invoked by pika.

reconnect()

Will be invoked by the IOLoop timer if the connection is closed. See the on_connection_closed method.

run()

Run the example consumer by connecting to RabbitMQ and then starting the IOLoop to block and allow the SelectConnection to operate.

class tavrida.amqp_driver.pika_async.BindingCreator(config, queue_name, exchange_name, routing_key)

Bases: object

close_connection()

This method closes the connection to RabbitMQ.

connect()

This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter.

Return type:pika.SelectConnection
create_binding()
class tavrida.amqp_driver.pika_async.ExchangeCreator(config, exchange_name, ex_type)

Bases: object

close_connection()

This method closes the connection to RabbitMQ.

connect()

This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter.

Return type:pika.SelectConnection
create_exchange()
class tavrida.amqp_driver.pika_async.Publisher(config, exchange_name, routing_key, message)

Bases: object

close_connection()

This method closes the connection to RabbitMQ.

connect()

This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter.

Return type:pika.SelectConnection
publish_message()
class tavrida.amqp_driver.pika_async.QueueCreator(config, queue_name)

Bases: object

close_connection()

This method closes the connection to RabbitMQ.

connect()

This method connects to RabbitMQ, returning the connection handle. When the connection is established, the on_connection_open method will be invoked by pika. If you want the reconnection to work, make sure you set stop_ioloop_on_close to False, which is not the default behavior of this adapter.

Return type:pika.SelectConnection
create_queue()
class tavrida.amqp_driver.pika_async.Reader(config, queue, preprocessor)

Bases: tavrida.amqp_driver.pika_async.BasePikaAsync, tavrida.amqp_driver.base.AbstractReader, tavrida.amqp_driver.base.AbstractWriter

Async pika client (reader + writer).

If RabbitMQ closes the connection, it will reopen it. You should look at the output, as there are limited reasons why the connection may be closed, which usually are tied to permission related issues or socket timeouts.

If the channel is closed, it will indicate a problem with one of the commands that were issued and that should surface in the output as well.

bind_queue(exchange_name, routing_key)
create_exchange(exchange_name, ex_type)
create_queue()

Setup the queue on RabbitMQ by invoking the Queue.Declare RPC command. When it is complete, the on_queue_declareok method will be invoked by pika.

Parameters:queue_name (str|unicode) – The name of the queue to declare.
on_message(unused_channel, basic_deliver, properties, body)

Invoked by pika when a message is delivered from RabbitMQ. The channel is passed for your convenience. The basic_deliver object that is passed in carries the exchange, routing key, delivery tag and a redelivered flag for the message. The properties passed in is an instance of BasicProperties with the message properties and the body is the message that was sent.

Parameters:
  • unused_channel (pika.channel.Channel) – The channel object
  • pika.Spec.Basic.Deliver – basic_deliver method
  • pika.Spec.BasicProperties – properties
  • body (str|unicode) – The message body
publish_message(exchange, routing_key, message)
stop()

Cleanly shutdown the connection to RabbitMQ by stopping the consumer with RabbitMQ. When RabbitMQ confirms the cancellation, on_cancelok will be invoked by pika, which will then closing the channel and connection. The IOLoop is started again because this method is invoked when CTRL-C is pressed raising a KeyboardInterrupt exception. This exception stops the IOLoop which needs to be running for pika to communicate with RabbitMQ. All of the commands issued prior to starting the IOLoop will be buffered but not processed.

stop_consuming()

Tell RabbitMQ that you would like to stop consuming by sending the Basic.Cancel RPC command.

class tavrida.amqp_driver.pika_async.Writer(config)

Bases: tavrida.amqp_driver.pika_async.BasePikaAsync, tavrida.amqp_driver.base.AbstractWriter

create_exchange(exchange_name, ex_type)
publish_message(exchange, routing_key, message)
class tavrida.amqp_driver.pika_async.WriterFactory

Bases: tavrida.amqp_driver.base.AbstractWriterFactory

get_writer(config)
get_writer_by_reader(reader)

tavrida.amqp_driver.pika_sync module

class tavrida.amqp_driver.pika_sync.PikaClient(config)

Bases: tavrida.amqp_driver.base.AbstractClient

channel
close_connection()
class tavrida.amqp_driver.pika_sync.Reader(config, queue, preprocessor)

Bases: tavrida.amqp_driver.pika_sync.PikaClient, tavrida.amqp_driver.base.AbstractReader

bind_queue(exchange_name, routing_key)
connect()
create_queue()
run()
stop()
class tavrida.amqp_driver.pika_sync.Writer(config)

Bases: tavrida.amqp_driver.pika_sync.PikaClient, tavrida.amqp_driver.base.AbstractWriter

connect()
create_exchange(exchange_name, ex_type)
classmethod create_from_reader(reader)
publish_message(exchange, routing_key, message)
class tavrida.amqp_driver.pika_sync.WriterFactory

Bases: tavrida.amqp_driver.base.AbstractWriterFactory

get_writer(config)
get_writer_by_reader(reader)

Module contents