def __call__(self):
        event = self.event
        queue_name = self.element.queue_name

        obj = event.object

        interpolator = IStringInterpolator(obj)

        body = interpolator(self.element.body.strip())

        if body:
            #send message to the RabbitMQ service
            rabbit = RabbitMQConnector(**rabbit_config)
            rabbit.open_connection()
            try:
                rabbit.declare_queue(queue_name)
                rabbit.send_message(queue_name, body)
            except Exception, err:
                logger.error(
                    'Sending \'%s\' in \'%s\' FAILED with error: %s',
                    body,
                    queue_name,
                    err)
            else:
                logger.info(
                    'Sending \'%s\' in \'%s\' OK',
                    body,
                    queue_name)
            rabbit.close_connection()
Esempio n. 2
0
 def bulk_update(self):
     """ Queries SDS for all datasets and injects messages in rabbitmq.
     """
     logger.info('START bulk update')
     result_json, msg = self.query_all_datasets()
     if msg:
         logger.error('BULK update: %s', msg)
     else:
         datasets_json = result_json['results']['bindings']
         logger.info('BULK update: %s datasets found', len(datasets_json))
         rabbit = RabbitMQConnector(**rabbit_config)
         rabbit.open_connection()
         rabbit.declare_queue(self.queue_name)
         counter = 1
         for item_json in datasets_json:
             dataset_identifier = item_json['id']['value']
             dataset_url = item_json['dataset']['value']
             action = 'update'
             body = '%(action)s|%(dataset_url)s|%(dataset_identifier)s' % {
                 'action': action,
                 'dataset_url': dataset_url,
                 'dataset_identifier': dataset_identifier}
             logger.info('BULK update %s: sending \'%s\' in \'%s\'', counter, body, self.queue_name)
             rabbit.send_message(self.queue_name, body)
             counter += 1
         rabbit.close_connection()
     logger.info('DONE bulk update')
Esempio n. 3
0
class ProxyProducer:
    """ Proxy Producer: its function is to emulate
        the EEA Portal that sends messages.
    """

    def __init__(self, queue_name):
        """ """
        self.queue_name = queue_name
        self.rabbit = RabbitMQConnector(**rabbit_config)

    def send_messages(self, howmany):
        """ Senf a message to the queue
        """
        logger.info('STARTING to send messages in \'%s\'', self.queue_name)
        self.rabbit.open_connection()
        self.rabbit.declare_queue(self.queue_name)
        for idx in range(0, howmany):
            action = choice(actions)
            dataset_identifier, dataset_url = choice(datasets.items())
            body = '%(action)s|%(dataset_url)s|%(dataset_identifier)s' % {
                'action': action,
                'dataset_url': dataset_url,
                'dataset_identifier': dataset_identifier}
            logger.info('SENDING \'%s\' in \'%s\'', body, self.queue_name)
            self.rabbit.send_message(self.queue_name, body)
        self.rabbit.close_connection()
        logger.info('DONE sending messages in \'%s\'', self.queue_name)
Esempio n. 4
0
    def __call__(self):
        related_action = self.element.related_action
        notification_subject = self.element.notification_subject
        notification_action = self.element.notification_action

        obj = self.event.object
        path = "/".join(obj.getPhysicalPath())

        tags = get_tags(obj)

        try:
            url = obj.absolute_url()
        except Exception:
            url = "N/A"

        try:
            content_title = obj.Title()
        except Exception:
            content_title = "N/A"

        try:
            actor = ContentHistoryView(
                obj,
                self.context.REQUEST).fullHistory()[0]['actor']['username']
        except Exception:
            try:
                actor = obj.Creator()
            except Exception:
                actor = "N/A"

        rabbit_config = get_rabbit_config()
        rabbit = RabbitMQConnector(**rabbit_config)
        try:
            rabbit.open_connection()
            rabbit.declare_queue(RABBIT_QUEUE)

            json_notification = {
                'notification_subject': notification_subject,
                'notification_action': notification_action,
                'content_url': url,
                'content_title': content_title,
                'actor': actor,
                'path': path,
                'tags': tags,
                'events': related_action,
            }
            message = json.dumps(json_notification)

            rabbit.send_message(RABBIT_QUEUE, message)
        except Exception:
            LOGGER.error(
                "RabbitMQ connection problem. "
                "Check client configuration: /@@rabbitmq-client-controlpanel."
                " See example in documentation.")
    def __call__(self):
        event = self.event
        queue_name = self.element.queue_name

        obj = event.object

        interpolator = IStringInterpolator(obj)

        body = interpolator(self.element.body.strip())

        if body:
            #send message to the RabbitMQ service
            rabbit = RabbitMQConnector(**rabbit_config)
            rabbit.open_connection()
            try:
                rabbit.declare_queue(queue_name)
                rabbit.send_message(queue_name, body)
            except Exception, err:
                logger.error('Sending \'%s\' in \'%s\' FAILED with error: %s',
                             body, queue_name, err)
            else:
                logger.info('Sending \'%s\' in \'%s\' OK', body, queue_name)
            rabbit.close_connection()