This module provides generic AMQP daemon and builder of common connection informations, which are defined as constants in edeposit.amqp.settings.
Daemon is used by edeposit_amqp_alephdaemon and edeposit_amqp_calibredaemon.
Bases: edeposit.amqp.pikadaemon.PikaDaemon
Parameters: |
|
---|
Note
react_fn parameter is expected to be function, which gets two parameters - message (some form of message, it can be also namedtuple), and UUID containing unique identificator of the message.
Example of function used as react_fn parameter:
def reactToAMQPMessage(message, UUID):
response = None
if message == 1:
return 2
elif message == "Hello":
return "Hi"
elif type(message) == dict:
return {1: 2}
raise UserWarning("Unrecognized message")
As you can see, protocol is pretty easy. You get message, to which you react somehow and return response. Thats all.
React to received message - deserialize it, add it to users reaction function stored in self.react_fn and send back result.
If Exception is thrown during process, it is sent back instead of message.
Note
In case of Exception, response message doesn’t have useful body, but in headers is stored following (string) parameters:
This allows you to react to unexpected cases at the other end of the AMQP communication.
Connection object builder.
Parameters: | virtualhost (str) – selected virtualhost in rabbitmq |
---|---|
Returns: | pika.ConnectionParameters – object filled by constants from edeposit.amqp.settings. |