Generic AMQP blocking communication daemon server.
Usage is simple - just inherit the class and override PikaDaemon.onMessageReceived().
You can send messages back using either PikaDaemon.sendMessage() or PikaDaemon.sendResponse(). Fist one allows you to send message everywhere, second one send message to the queue defined by constructor.
- class edeposit.amqp.pikadaemon.PikaDaemon(connection_param, queue, output_exchange, output_key)¶
Pika and Daemon wrapper for handling AMQP connections.
Acknowledge, that message was received.
This will in some cases (depends on settings of RabbitMQ) remove the message from the message queue.
This method just handles AMQP connection details and receive loop.
Don’t override this method!
Called when daemon is stopped. Basically just AMQP’s .close() functions to ensure clean exit.
You can override this, but don’t forget to call it thru super(), or the AMQP communication won’t be closed properly!
- onMessageReceived(method_frame, properties, body)¶
Callback which is called every time when message is received.
You SHOULD override this.
It is expected, that method returns True, if you want to automatically ack the received message, which can be important in some situations, because otherwise the message will be held in message queue until someone will ack it.
You don’t have to return True/False - you can ack the message yourself, by calling ack().
Good design choice is to ack the message AFTER you process it, to be sure, that message is processed properly and can be removed from queue.
- sendMessage(exchange, routing_key, message, properties=None, UUID=None)¶
With this function, you can send message to exchange.
- exchange (str) – name of exchange you want to message to be delivered
- routing_key (str) – which routing key to use in headers of message
- message (str) – body of message
- properties (dict ,optional) – properties of message - if not used, or set to None, self.content_type and delivery_mode=2 (persistent) is used
- UUID (str, optional) – UUID of the message. If set, it is included into properties of the message.
- sendResponse(message, UUID, routing_key)¶
Send message to self.output_exchange with routing key self.output_key, self.content_type in delivery_mode=2.