From 0604e5ef1cdd8b48bc7cc13f312e9ad00e2e78a1 Mon Sep 17 00:00:00 2001 From: emalin Date: Tue, 25 Jul 2017 12:47:05 +0300 Subject: [PATCH] listener_service - enable listen to multiple topics + specify exchange name Change-Id: I689c3bd3f39ed38c86710341b3778b11f9e48f68 --- vitrage/datasources/__init__.py | 10 +++++++--- vitrage/datasources/listener_service.py | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/vitrage/datasources/__init__.py b/vitrage/datasources/__init__.py index 4608d4698..459512ca4 100644 --- a/vitrage/datasources/__init__.py +++ b/vitrage/datasources/__init__.py @@ -45,9 +45,13 @@ OPTS = [ min=1, help='Time to wait until retrying to snapshot the datasource' ' in case of fault'), - cfg.StrOpt('notification_topic', - default='vitrage_notifications', - help='Vitrage configured notifications topic'), + cfg.ListOpt('notification_topics', + default=['vitrage_notifications'], + help='Vitrage configured notifications topic', + deprecated_name='notification_topic'), + cfg.StrOpt('notification_exchange', + required=False, + help='Exchange that is used for notifications.'), cfg.StrOpt('notification_topic_collector', default='vitrage_collector_notifications', help='The topic on which event will be sent from the ' diff --git a/vitrage/datasources/listener_service.py b/vitrage/datasources/listener_service.py index bc4e8a417..f7605d247 100644 --- a/vitrage/datasources/listener_service.py +++ b/vitrage/datasources/listener_service.py @@ -33,8 +33,10 @@ class ListenerService(os_service.Service): self.enrich_callbacks_by_events = \ self._create_callbacks_by_events_dict(drivers, conf) - topic = conf.datasources.notification_topic - self.listener = self._get_topic_listener(conf, topic, callback) + topics = conf.datasources.notification_topics + exchange = conf.datasources.notification_exchange + self.listener = self._get_topics_listener( + conf, topics, callback, exchange) def start(self): LOG.info("Vitrage data source Listener Service - Starting...") @@ -65,10 +67,11 @@ class ListenerService(os_service.Service): return ret - def _get_topic_listener(self, conf, topic, callback): + def _get_topics_listener(self, conf, topics, callback, exchange=None): # Create a listener for each topic transport = messaging.get_transport(conf) - targets = [oslo_messaging.Target(topic=topic)] + targets = [oslo_messaging.Target(exchange=exchange, topic=topic) + for topic in topics] return messaging.get_notification_listener( transport,