bci.publisher.drivers package¶
Submodules¶
bci.publisher.drivers.find_driver module¶
-
bci.publisher.drivers.find_driver.find_driver(scheme)¶ Finds the driver corresponding to scheme.
- Parameters
scheme (str) – The message queue scheme.
- Returns
The driver corresponding to scheme.
- Raises
ValueError – If scheme is unknown.
bci.publisher.drivers.rabbitmq module¶
-
class
bci.publisher.drivers.rabbitmq.RabbitmqDriver(host, port, is_subscriber)¶ Bases:
objectRepresents a RabbitMQ message-broker driver.
-
host¶ RabbitMQ server’s IP address.
- Type
str
-
port¶ RabbitMQ server’s port.
- Type
int
-
is_subscriber¶ If true, this publisher is also a subscriber.
- Type
bool
- Parameters
host (str) – RabbitMQ server’s IP address.
port (int) – RabbitMQ server’s port.
is_subscriber (bool) – If true, this publisher is also a subscriber.
- Raises
ValueError – If an invalid URL was provided.
-
publish(message, exchange, routing_key)¶ Publishes message to the queues on the exchange, while routing it by the routing key.
- Parameters
message (str) – JSON-formatted message to be published.
exchange (str) – The name of the exchange to publish to.
routing_key (str) – The routing key to bind on.
- Raises
AssertionError – If this driver is not a publisher.
exceptions.ChannelWrongStateError – If the created channel is not in the OPEN state.
-
scheme= 'rabbitmq'¶
-
subscribe(exchange, routing_key, queue, callback)¶ Subscribes queue to exchange on routing_key, and starts the created channel to consume messages.
- Parameters
exchange (str) – The name of the exchange to subscribe to.
routing_key (str) – The routing key to bind on.
queue (str) – The queue to consume from.
callback (callable) – The function to call when consuming with the following signature: callback(channel: pika.Channel, method: pika.spec.Basic.Deliver, properties: pika.spec.BasicProperties, body:bytes)
- Raises
AssertionError – If this driver is not a subscriber.
exceptions.ChannelWrongStateError – If the created channel is not in the OPEN state.
-