PikaDaemon¶
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)[source]¶ Bases:
edeposit.amqp.daemonwrapper.DaemonRunnerWrapper
Pika and Daemon wrapper for handling AMQP connections.
Parameters: -
ack
(ack_delivery_tag)[source]¶ Acknowledge, that message was received.
Note
This will in some cases (depends on settings of RabbitMQ) remove the message from the message queue.
-
body
()[source]¶ This method just handles AMQP connection details and receive loop.
Warning
Don’t override this method!
-
onExit
()[source]¶ 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)[source]¶ Callback which is called every time when message is received.
Warning
You SHOULD override this.
Note
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()
.Note
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)[source]¶ With this function, you can send message to exchange.
Parameters: - 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
anddelivery_mode=2
(persistent) is used - UUID (str, optional) – UUID of the message. If set, it is included
into
properties
of the message.
-