nsq/reader.py
def connect_to_nsqd(self, host, port):
        """
        Adds a connection to ``nsqd`` at the specified address.

        :param host: the address to connect to
        :param port: the port to connect to
        """
        assert isinstance(host, string_types)
        assert isinstance(port, int)

        conn = AsyncConn(host, port, **self.conn_kwargs)
        conn.on('identify', self._on_connection_identify)
        conn.on('identify_response', self._on_connection_identify_response)
        conn.on('auth', self._on_connection_auth)
        conn.on('auth_response', self._on_connection_auth_response)
        conn.on('error', self._on_connection_error)
        conn.on('close', self._on_connection_close)
        conn.on('ready', self._on_connection_ready)
        conn.on('message', self._on_message)
        conn.on('heartbeat', self._on_heartbeat)
        conn.on('backoff', functools.partial(self._on_backoff_resume, success=False))
        conn.on('resume', functools.partial(self._on_backoff_resume, success=True))
        conn.on('continue', functools.partial(self._on_backoff_resume, success=None))

        if conn.id in self.conns:
            return

        # only attempt to re-connect once every 10s per destination
        # this throttles reconnects to failed endpoints
        now = time.time()
        last_connect_attempt = self.connection_attempts.get(conn.id)
        if last_connect_attempt and last_connect_attempt > now - 10:
            return
        self.connection_attempts[conn.id] = now

        logger.info('[%s:%s] connecting to nsqd', conn.id, self.name)
        conn.connect()

        return conn
def connect_to_nsqd(self, host, port):
        assert isinstance(host, string_types)
        assert isinstance(port, int)

        conn = AsyncConn(host, port, **self.conn_kwargs)
        conn.on('identify', self._on_connection_identify)
        conn.on('identify_response', self._on_connection_identify_response)
        conn.on('auth', self._on_connection_auth)
        conn.on('auth_response', self._on_connection_auth_response)
        conn.on('error', self._on_connection_error)
        conn.on('close', self._on_connection_close)
        conn.on('ready', self._on_connection_ready)
        conn.on('message', self._on_message)
        conn.on('heartbeat', self._on_heartbeat)
        conn.on('backoff', functools.partial(self._on_backoff_resume, success=False))
        conn.on('resume', functools.partial(self._on_backoff_resume, success=True))
        conn.on('continue', functools.partial(self._on_backoff_resume, success=None))

        if conn.id in self.conns:
            return

        # only attempt to re-connect once every 10s per destination
        # this throttles reconnects to failed endpoints
        now = time.time()
        last_connect_attempt = self.connection_attempts.get(conn.id)
        if last_connect_attempt and last_connect_attempt > now - 10:
            return
        self.connection_attempts[conn.id] = now

        logger.info('[%s:%s] connecting to nsqd', conn.id, self.name)
        conn.connect()

        return conn
def connect_to_nsqd ( self , host , port ) : assert isinstance ( host , string_types ) assert isinstance ( port , int ) conn = AsyncConn ( host , port , * * self . conn_kwargs ) conn . on ( 'identify' , self . _on_connection_identify ) conn . on ( 'identify_response' , self . _on_connection_identify_response ) conn . on ( 'auth' , self . _on_connection_auth ) conn . on ( 'auth_response' , self . _on_connection_auth_response ) conn . on ( 'error' , self . _on_connection_error ) conn . on ( 'close' , self . _on_connection_close ) conn . on ( 'ready' , self . _on_connection_ready ) conn . on ( 'message' , self . _on_message ) conn . on ( 'heartbeat' , self . _on_heartbeat ) conn . on ( 'backoff' , functools . partial ( self . _on_backoff_resume , success = False ) ) conn . on ( 'resume' , functools . partial ( self . _on_backoff_resume , success = True ) ) conn . on ( 'continue' , functools . partial ( self . _on_backoff_resume , success = None ) ) if conn . id in self . conns : return # only attempt to re-connect once every 10s per destination # this throttles reconnects to failed endpoints now = time . time ( ) last_connect_attempt = self . connection_attempts . get ( conn . id ) if last_connect_attempt and last_connect_attempt > now - 10 : return self . connection_attempts [ conn . id ] = now logger . info ( '[%s:%s] connecting to nsqd' , conn . id , self . name ) conn . connect ( ) return conn
Adds a connection to ``nsqd`` at the specified address.

        :param host: the address to connect to
        :param port: the port to connect to
Adds a connection to nsqd at the specified address .