Пример #1
0
    def _watch_configurators(self, event):
        """
        监测某个interface中provider的权重的变化信息
        :param event:
        :return:
        """
        path = event.path
        logger.debug('zookeeper node changed: {}'.format(path))
        interface = path.split('/')[2]

        # 试图从配置中取出权重相关的信息
        configurators = self.zk.get_children(
            DUBBO_ZK_CONFIGURATORS.format(interface),
            watch=self._watch_configurators)
        if configurators:
            configurators = list(map(parse_url, configurators))
            conf = {}
            for configurator in configurators:
                conf[configurator['host']] = configurator['fields'].get(
                    'weight', 100)
            logger.debug('{} configurators: {}'.format(interface, conf))
            self.weights[interface] = conf
        else:
            logger.debug('No configurator for interface {}')
            self.weights[interface] = {}
Пример #2
0
 def __resubscribe(self):
     """
     由于与Zookeeper的连接断开,所以需要重新订阅消息
     :return:
     """
     for interface in self.hosts.keys():
         self.zk.get_children(DUBBO_ZK_PROVIDERS.format(interface), watch=self._watch_children)
         self.zk.get_children(DUBBO_ZK_CONFIGURATORS.format(interface), watch=self._watch_configurators)
Пример #3
0
 def _get_configurators_from_zk(self, interface):
     """
     试图从配置中取出权重相关的信息
     :param interface:
     :return:
     """
     configurators = self.zk.get_children(DUBBO_ZK_CONFIGURATORS.format(interface), watch=self._watch_configurators)
     if configurators:
         configurators = map(parse_url, configurators)
         conf = {}
         for configurator in configurators:
             conf[configurator['host']] = configurator['fields'].get('weight', 100)  # 默认100
         self.weights[interface] = conf