message_queues package¶
message_queues module¶
-
class
mindreader.drivers.message_queues.message_queue.MessageQueue(url)¶ Bases:
objectA message queue that allows sending and consuming messages.
To add a new message queue, add a file named <name>_mq.py to the current-package, with a class named <name>MQ, which has an attribute named ‘prefix’ (string), which is the message queue name. It should implement the functions below. Make sure you update the prefix you chose in ‘supported_dbs’ above.
-
consume(topic, handler, queue='')¶ Listens to an exchange, and handle messages received. Note that this function is blocking.
- Parameters
topic – the name of the exchange to subscribe to.
handler – a function that receives
queue – optional parameter, allows multiple consumers to split the load between them. if not supported, a unique queue is generated.
- Returns
-
publish(topic, message)¶ Publishes a message to the queue.
- Parameters
topic – the name of the exchange to post into (consumers will have to use that to receive messages).
message – the data, encoded in JSON format.
-
-
mindreader.drivers.message_queues.message_queue.load_message_queues()¶ Loads dynamically all the available message queues.
-
mindreader.drivers.message_queues.message_queue.supported_mqs= {'rabbitmq': <class 'message_queues.rabbit_mq.RabbitMQ'>}¶ Mapping of the supported message queses, loaded dynamically. Currently available: RabbitMQ - ‘rabbitmq’