def build_notification_handler(self, topic_names, endpoints=()): serializer = rpc.RequestContextSerializer(rpc.JsonPayloadSerializer()) targets = [om.Target(topic=topic_name) for topic_name in topic_names] return om.get_notification_listener( self.notification_transport, targets, endpoints, executor='eventlet', serializer=serializer, allow_requeue=False)
def build_topic_handler(self, topic_name, endpoints=()): access_policy = dispatcher.DefaultRPCAccessPolicy serializer = rpc.RequestContextSerializer(rpc.JsonPayloadSerializer()) target = om.Target( topic=topic_name, # For compatibility, we can override it with 'host' opt server=CONF.host or socket.gethostname(), version=self.api_version, ) return om.get_rpc_server( self.transport, target, endpoints, executor='eventlet', serializer=serializer, access_policy=access_policy)
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)
def __init__(self, publisher_id, conductor_topic, status_topic, api_version=API_VERSION): super(MessagingCore, self).__init__() self.serializer = rpc.RequestContextSerializer( base.WatcherObjectSerializer()) self.publisher_id = publisher_id self.api_version = api_version self.conductor_topic = conductor_topic self.status_topic = status_topic self.conductor_topic_handler = self.build_topic_handler( conductor_topic) self.status_topic_handler = self.build_topic_handler(status_topic) self._conductor_client = None self._status_client = None
def __init__(self, manager_class): super(Service, self).__init__() self.manager = manager_class() self.publisher_id = self.manager.publisher_id self.api_version = self.manager.api_version self.conductor_topic = self.manager.conductor_topic self.status_topic = self.manager.status_topic self.notification_topics = self.manager.notification_topics self.conductor_endpoints = [ ep(self) for ep in self.manager.conductor_endpoints ] self.status_endpoints = [ ep(self.publisher_id) for ep in self.manager.status_endpoints ] self.notification_endpoints = self.manager.notification_endpoints self.serializer = rpc.RequestContextSerializer( base.WatcherObjectSerializer()) self._transport = None self._notification_transport = None self._conductor_client = None self._status_client = None self.conductor_topic_handler = None self.status_topic_handler = None self.notification_handler = None self.heartbeat = None if self.conductor_topic and self.conductor_endpoints: self.conductor_topic_handler = self.build_topic_handler( self.conductor_topic, self.conductor_endpoints) if self.status_topic and self.status_endpoints: self.status_topic_handler = self.build_topic_handler( self.status_topic, self.status_endpoints) if self.notification_topics and self.notification_endpoints: self.notification_handler = self.build_notification_handler( self.notification_topics, self.notification_endpoints) self.service_name = self.manager.service_name if self.service_name: self.heartbeat = ServiceHeartbeat( service_name=self.manager.service_name)
def build_notifier(self): serializer = rpc.RequestContextSerializer(rpc.JsonPayloadSerializer()) return om.Notifier(self.__transport, publisher_id=self.publisher_id, topic=self.topic_name, serializer=serializer)