#!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- # # Author : Pierre-Elliott Bécue # License : GPLv3 # Date : 29/04/2014 import argparse import cranslib.clogger as clogger import cmb import cPickle import socket import gestion.config.trigger as trigger_config import gestion.affichage as affichage import sys logger = clogger.CLogger("transcriptor", "info") def process_event(body): """ Makes the transcription between the ldap modlist generated by lc_ldap and sent to the event queue and the message one have to send to the services. Example : {} """ class EvenementListener(cmb.AsynchronousConsumer): """ Gestionnaire d'événement """ def on_message(self, channel, basic_deliver, properties, body): """Invoked by pika when a message is delivered from RabbitMQ. The channel is passed for your convenience. The basic_deliver object that is passed in carries the exchange, routing key, delivery tag and a redelivered flag for the message. The properties passed in is an instance of BasicProperties with the message properties and the body is the message that was sent. :param pika.channel.Channel channel: The channel object :param pika.Spec.Basic.Deliver: basic_deliver method :param pika.Spec.BasicProperties: properties :param str|unicode body: The message body """ origin = properties.app_id message_id = properties.message_id logger.info('Received message # %s from %s: %s', basic_deliver.delivery_tag, properties.app_id, body) body = cPickle.loads(body) process_event(body) self.acknowledge_message(basic_deliver.delivery_tag) def run(self): """Run the example consumer by connecting to RabbitMQ and then starting the IOLoop to block and allow the SelectConnection to operate. """ logger.info("""Crans Message Broker +--------------------------------------------+ | Welcome on Transcriptor | +--------------------------------------------+""") self._connection = self.connect() self.add_queue("trigger-event", "trigger.event") self._connection.ioloop.start() def daemonize(): listener = EvenementListener(trigger_config.master, "trigger", "topic") try: listener.run() except KeyboardInterrupt: logger.warning("Caught SIGINT, will now go for shutdown.") listener.stop() if __name__ == '__main__': # Daemonize the trigger app, in order to listen and execute commands from civet. daemonize()