Python oslo_messaging.get_notification_listener() Examples

The following are 6 code examples of oslo_messaging.get_notification_listener(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_messaging , or try the search function .
Example #1
Source File: listener.py    From searchlight with Apache License 2.0 6 votes vote down vote up
def main():
    if len(sys.argv) < 2:
        print("Supply an exchange")
        sys.exit(0)

    exchange = sys.argv[1]
    pool = sys.argv[2] if len(sys.argv) > 2 else None

    transport = oslo_messaging.get_notification_transport(
        cfg.CONF,
        url='rabbit://%s:%s@%s' % (username, password, host))
    targets = [oslo_messaging.Target(topic=topic, exchange=exchange)]
    endpoints = [EP()]
    oslo_listener = oslo_messaging.get_notification_listener(
        transport, targets, endpoints, pool=pool, executor='threading')
    try:
        print("Started")
        oslo_listener.start()
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Stopping")
        oslo_listener.stop()
        oslo_listener.wait() 
Example #2
Source File: listener.py    From searchlight with Apache License 2.0 6 votes vote down vote up
def start(self):
        super(ListenerService, self).start()
        transport = oslo_messaging.get_notification_transport(CONF)
        targets = [
            oslo_messaging.Target(topic=pl_topic, exchange=pl_exchange)
            for pl_topic, pl_exchange in self.topics_exchanges_set
        ]
        endpoints = [
            NotificationEndpoint(self.plugins, PipelineManager(self.plugins))
        ]
        listener = oslo_messaging.get_notification_listener(
            transport,
            targets,
            endpoints,
            executor='threading',
            pool=CONF.listener.notifications_pool)

        listener.start()
        self.listeners.append(listener) 
Example #3
Source File: rpc.py    From designate with Apache License 2.0 5 votes vote down vote up
def get_notification_listener(targets, endpoints, serializer=None, pool=None):
    if NOTIFICATION_TRANSPORT is None:
        raise AssertionError("'NOTIFICATION_TRANSPORT' must not be None")
    if serializer is None:
        serializer = JsonPayloadSerializer()
    return messaging.get_notification_listener(
        NOTIFICATION_TRANSPORT,
        targets,
        endpoints,
        executor='eventlet',
        pool=pool,
        serializer=serializer
    ) 
Example #4
Source File: messaging.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def get_notification_listener(transport, targets, endpoints,
                              allow_requeue=False):
    """Return a configured oslo_messaging notification listener."""
    return oslo_msg.get_notification_listener(
        transport, targets, endpoints, allow_requeue=allow_requeue) 
Example #5
Source File: service.py    From watcher with Apache License 2.0 5 votes vote down vote up
def build_notification_handler(self, topic_names, endpoints=()):
        serializer = rpc.RequestContextSerializer(rpc.JsonPayloadSerializer())
        targets = []
        for topic in topic_names:
            kwargs = {}
            if '.' in topic:
                exchange, topic = topic.split('.')
                kwargs['exchange'] = exchange
            kwargs['topic'] = topic
            targets.append(om.Target(**kwargs))
        return om.get_notification_listener(
            self.notification_transport, targets, endpoints,
            executor='eventlet', serializer=serializer,
            allow_requeue=False, pool=CONF.host) 
Example #6
Source File: health_manager.py    From senlin with Apache License 2.0 5 votes vote down vote up
def ListenerProc(exchange, project_id, cluster_id, recover_action):
    """Thread procedure for running an event listener.

    :param exchange: The control exchange for a target service.
    :param project_id: The ID of the project to filter.
    :param cluster_id: The ID of the cluster to filter.
    :param recover_action: The health policy action name.
    """
    transport = messaging.get_notification_transport(cfg.CONF)

    if exchange == cfg.CONF.health_manager.nova_control_exchange:
        endpoint = nova_endpoint.NovaNotificationEndpoint(
            project_id, cluster_id, recover_action
        )

    else:
        endpoint = heat_endpoint.HeatNotificationEndpoint(
            project_id, cluster_id, recover_action
        )

    listener = messaging.get_notification_listener(
        transport, [endpoint.target], [endpoint], executor='threading',
        pool='senlin-listeners'
    )

    listener.start()