Exemplo n.º 1
0
    def __init__(self, conf, server_params=None):
        self.consumers = []
        self.conf = conf
        self.max_retries = self.conf.rabbit_max_retries
        # Try forever?
        if self.max_retries <= 0:
            self.max_retries = None
        self.interval_start = self.conf.rabbit_retry_interval
        self.interval_stepping = self.conf.rabbit_retry_backoff
        # max retry-interval = 30 seconds
        self.interval_max = 30
        self.memory_transport = False

        if server_params is None:
            server_params = {}
        # Keys to translate from server_params to kombu params
        server_params_to_kombu_params = {'username': '******'}

        ssl_params = self._fetch_ssl_params()
        params_list = []
        for adr in self.conf.rabbit_hosts:
            hostname, port = network_utils.parse_host_port(
                adr, default_port=self.conf.rabbit_port)

            params = {
                'hostname': hostname,
                'port': port,
                'userid': self.conf.rabbit_userid,
                'password': self.conf.rabbit_password,
                'login_method': self.conf.rabbit_login_method,
                'virtual_host': self.conf.rabbit_virtual_host,
            }

            for sp_key, value in six.iteritems(server_params):
                p_key = server_params_to_kombu_params.get(sp_key, sp_key)
                params[p_key] = value

            if self.conf.fake_rabbit:
                params['transport'] = 'memory'
            if self.conf.rabbit_use_ssl:
                params['ssl'] = ssl_params

            params_list.append(params)

        self.params_list = params_list

        brokers_count = len(self.params_list)
        self.next_broker_indices = itertools.cycle(range(brokers_count))

        self.memory_transport = self.conf.fake_rabbit

        self.connection = None
        self.do_consume = None
        self.reconnect()
Exemplo n.º 2
0
    def __init__(self, conf, server_params=None):
        self.consumers = []
        self.conf = conf
        self.max_retries = self.conf.rabbit_max_retries
        # Try forever?
        if self.max_retries <= 0:
            self.max_retries = None
        self.interval_start = self.conf.rabbit_retry_interval
        self.interval_stepping = self.conf.rabbit_retry_backoff
        # max retry-interval = 30 seconds
        self.interval_max = 30
        self.memory_transport = False

        if server_params is None:
            server_params = {}
        # Keys to translate from server_params to kombu params
        server_params_to_kombu_params = {'username': '******'}

        ssl_params = self._fetch_ssl_params()
        params_list = []
        for adr in self.conf.rabbit_hosts:
            hostname, port = network_utils.parse_host_port(
                adr, default_port=self.conf.rabbit_port)

            params = {
                'hostname': hostname,
                'port': port,
                'userid': self.conf.rabbit_userid,
                'password': self.conf.rabbit_password,
                'login_method': self.conf.rabbit_login_method,
                'virtual_host': self.conf.rabbit_virtual_host,
            }

            for sp_key, value in six.iteritems(server_params):
                p_key = server_params_to_kombu_params.get(sp_key, sp_key)
                params[p_key] = value

            if self.conf.fake_rabbit:
                params['transport'] = 'memory'
            if self.conf.rabbit_use_ssl:
                params['ssl'] = ssl_params

            params_list.append(params)

        random.shuffle(params_list)
        self.params_list = itertools.cycle(params_list)

        self.memory_transport = self.conf.fake_rabbit

        self.connection = None
        self.do_consume = None
        self.reconnect()
Exemplo n.º 3
0
    def __init__(self, conf, url):
        if not qpid_messaging:
            raise ImportError("Failed to import qpid.messaging")

        self.connection = None
        self.session = None
        self.consumers = {}
        self.conf = conf

        self.brokers_params = []
        if url.hosts:
            for host in url.hosts:
                params = {
                    'username': host.username or '',
                    'password': host.password or '',
                }
                if host.port is not None:
                    params['host'] = '%s:%d' % (host.hostname, host.port)
                else:
                    params['host'] = host.hostname
                self.brokers_params.append(params)
        else:
            # Old configuration format
            for adr in self.conf.qpid_hosts:
                hostname, port = network_utils.parse_host_port(
                    adr, default_port=5672)

                params = {
                    'host': '%s:%d' % (hostname, port),
                    'username': self.conf.qpid_username,
                    'password': self.conf.qpid_password,
                }
                self.brokers_params.append(params)

        random.shuffle(self.brokers_params)
        self.brokers = itertools.cycle(self.brokers_params)

        self.reconnect()
Exemplo n.º 4
0
    def __init__(self, conf, url):
        self.consumers = []
        self.conf = conf
        self.max_retries = self.conf.rabbit_max_retries
        # Try forever?
        if self.max_retries <= 0:
            self.max_retries = None
        self.interval_start = self.conf.rabbit_retry_interval
        self.interval_stepping = self.conf.rabbit_retry_backoff
        # max retry-interval = 30 seconds
        self.interval_max = 30
        self.memory_transport = False

        ssl_params = self._fetch_ssl_params()

        if url.virtual_host is not None:
            virtual_host = url.virtual_host
        else:
            virtual_host = self.conf.rabbit_virtual_host

        self.brokers_params = []
        if url.hosts:
            for host in url.hosts:
                params = {
                    'hostname': host.hostname,
                    'port': host.port or 5672,
                    'userid': host.username or '',
                    'password': host.password or '',
                    'login_method': self.conf.rabbit_login_method,
                    'virtual_host': virtual_host
                }
                if self.conf.fake_rabbit:
                    params['transport'] = 'memory'
                if self.conf.rabbit_use_ssl:
                    params['ssl'] = ssl_params

                self.brokers_params.append(params)
        else:
            # Old configuration format
            for adr in self.conf.rabbit_hosts:
                hostname, port = network_utils.parse_host_port(
                    adr, default_port=self.conf.rabbit_port)

                params = {
                    'hostname': hostname,
                    'port': port,
                    'userid': self.conf.rabbit_userid,
                    'password': self.conf.rabbit_password,
                    'login_method': self.conf.rabbit_login_method,
                    'virtual_host': virtual_host
                }

                if self.conf.fake_rabbit:
                    params['transport'] = 'memory'
                if self.conf.rabbit_use_ssl:
                    params['ssl'] = ssl_params

                self.brokers_params.append(params)

        random.shuffle(self.brokers_params)
        self.brokers = itertools.cycle(self.brokers_params)

        self.memory_transport = self.conf.fake_rabbit

        self.connection = None
        self.do_consume = None
        self.reconnect()