Exemple #1
0
    def _get_conn(self, host, port, afi, node_id='bootstrap'):
        """Get or create a connection to a broker using host and port"""
        host_key = (host, port)
        if host_key not in self._conns:

            self._conns[host_key] = BrokerConnection(
                host, port, afi,
                request_timeout_ms=self.timeout * 1000,
                client_id=self.client_id,
                metrics=self._metrics_registry,
                metric_group_prefix='simple-client',
                node_id=node_id,
            )

        conn = self._conns[host_key]
        conn.connect()
        if conn.connected():
            return conn

        timeout = time.time() + self.timeout
        while time.time() < timeout and conn.connecting():
            if conn.connect() is ConnectionStates.CONNECTED:
                break
            else:
                time.sleep(0.05)
        else:
            conn.close()
            raise ConnectionError("%s:%s (%s)" % (host, port, afi))
        return conn
Exemple #2
0
    def _get_conn(self, host, port, afi):
        """Get or create a connection to a broker using host and port"""
        host_key = (host, port)
        if host_key not in self._conns:
            self._conns[host_key] = BrokerConnection(
                host,
                port,
                afi,
                request_timeout_ms=self.timeout * 1000,
                client_id=self.client_id)

        conn = self._conns[host_key]
        conn.connect()
        if conn.connected():
            return conn

        timeout = time.time() + self.timeout
        while time.time() < timeout and conn.connecting():
            if conn.connect() is ConnectionStates.CONNECTED:
                break
            else:
                time.sleep(0.05)
        else:
            conn.close()
            raise ConnectionError("%s:%s (%s)" % (host, port, afi))
        return conn
    def _get_conn(self, host, port, afi):
        """Get or create a connection to a broker using host and port"""
        host_key = (host, port)
        if host_key not in self._conns:
            self._conns[host_key] = BrokerConnection(
                host, port, afi,
                request_timeout_ms=self.timeout * 1000,
                client_id=self.client_id
            )

        conn = self._conns[host_key]
        if not conn.connect_blocking(self.timeout):
            conn.close()
            raise ConnectionError("%s:%s (%s)" % (host, port, afi))
        return conn