Example #1
0
 def _on_message_touch(self, message, **kwargs):
     try:
         self.send(nsq.touch(message.id))
     except Exception, e:
         self.close()
         self.trigger('error', conn=self,
                      error=nsq.SendError('failed to send TOUCH %s' % message.id, e))
Example #2
0
 def _on_connect(self, **kwargs):
     identify_data = {
         'short_id': self.short_hostname,
         'long_id': self.hostname,
         'heartbeat_interval': self.heartbeat_interval,
         'feature_negotiation': True,
         'tls_v1': self.tls_v1,
         'snappy': self.snappy,
         'deflate': self.deflate,
         'deflate_level': self.deflate_level,
         'output_buffer_timeout': self.output_buffer_timeout,
         'output_buffer_size': self.output_buffer_size,
         'sample_rate': self.sample_rate,
         'user_agent': self.user_agent
     }
     self.trigger('identify', conn=self, data=identify_data)
     self.on('response', self._on_identify_response)
     try:
         self.send(nsq.identify(identify_data))
     except Exception, e:
         self.close()
         self.trigger('error',
                      conn=self,
                      error=nsq.SendError('failed to bootstrap connection',
                                          e))
Example #3
0
 def _on_message_finish(self, message, **kwargs):
     self.in_flight -= 1
     try:
         self.send(nsq.finish(message.id))
     except Exception, e:
         self.close()
         self.trigger('error', conn=self,
                      error=nsq.SendError('failed to send FIN %s' % message.id, e))
Example #4
0
 def send_rdy(self, value):
     try:
         self.send(nsq.ready(value))
     except Exception, e:
         self.close()
         self.trigger('error', conn=self,
                      error=nsq.SendError('failed to send RDY %d' % value, e))
         return False
Example #5
0
 def _on_message_requeue(self, message, backoff=True, time_ms=-1, **kwargs):
     self.in_flight -= 1
     try:
         time_ms = self.requeue_delay * message.attempts * 1000 if time_ms < 0 else time_ms
         self.send(nsq.requeue(message.id, time_ms))
     except Exception, e:
         self.close()
         self.trigger('error', conn=self, error=nsq.SendError(
             'failed to send REQ %s @ %d' % (message.id, time_ms), e))
Example #6
0
    def _on_response_continue(self, data, **kwargs):
        if self._features_to_enable:
            feature = self._features_to_enable.pop(0)
            if feature == 'tls_v1':
                self.upgrade_to_tls(self.tls_options)
            elif feature == 'snappy':
                self.upgrade_to_snappy()
            elif feature == 'deflate':
                self.upgrade_to_deflate()
            # the server will 'OK' after these conneciton upgrades triggering another response
            return

        self.off('response', self._on_response_continue)
        if self.auth_secret and self._authentication_required:
            self.on('response', self._on_auth_response)
            self.trigger('auth', conn=self, data=self.auth_secret)
            try:
                self.send(nsq.auth(self.auth_secret))
            except Exception, e:
                self.close()
                self.trigger('error', conn=self, error=nsq.SendError('Error sending AUTH', e))
            return