Esempio n. 1
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))
Esempio n. 2
0
 def data_callback(c, data):
     unpacked = nsq.unpack_response(data)
     if unpacked[0] == nsq.FRAME_TYPE_MESSAGE:
         c.send(nsq.ready(1))
         msg = nsq.decode_message(unpacked[1])
         print msg.id, msg.body
         c.send(nsq.finish(msg.id))
Esempio n. 3
0
 def data_callback(c, data):
     unpacked = nsq.unpack_response(data)
     if unpacked[0] == nsq.FRAME_TYPE_MESSAGE:
         c.send(nsq.ready(1))
         msg = nsq.decode_message(unpacked[1])
         print msg.id, msg.body
         c.send(nsq.finish(msg.id))
Esempio n. 4
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))
Esempio n. 5
0
        while True:
            if len(self.buffer) >= size:
                break
            packet = self.s.recv(4096)
            if not packet:
                raise Exception("failed to read %d" % size)
            self.buffer += packet
        data = self.buffer[:size]
        self.buffer = self.buffer[size:]
        return data

    def read_response(self):
        size = struct.unpack('>l', self._readn(4))[0]
        return self._readn(size)

    def send(self, data):
        self.s.send(data)


if __name__ == '__main__':
    c = SyncConn()
    c.connect("127.0.0.1", 4150)
    c.send(nsq.subscribe('test', 'ch', 'a', 'b'))
    for i in xrange(10):
        c.send(nsq.ready(1))
        resp = c.read_response()
        unpacked = nsq.unpack_response(resp)
        msg = nsq.decode_message(unpacked[1])
        print msg.id, msg.body
        c.send(nsq.finish(msg.id))
Esempio n. 6
0
        while True:
            if len(self.buffer) >= size:
                break
            packet = self.s.recv(4096)
            if not packet:
                raise Exception("failed to read %d" % size)
            self.buffer += packet
        data = self.buffer[:size]
        self.buffer = self.buffer[size:]
        return data
    
    def read_response(self):
        size = struct.unpack('>l', self._readn(4))[0]
        return self._readn(size)
    
    def send(self, data):
        self.s.send(data)


if __name__ == '__main__':
    c = SyncConn()
    c.connect("127.0.0.1", 4150)
    c.send(nsq.subscribe('test', 'ch', 'a', 'b'))
    for i in xrange(10):
        c.send(nsq.ready(1))
        resp = c.read_response()
        unpacked = nsq.unpack_response(resp)
        msg = nsq.decode_message(unpacked[1])
        print msg.id, msg.body
        c.send(nsq.finish(msg.id))