示例#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))
示例#2
0
文件: async.py 项目: JustinAzoff/nsq
 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))
示例#3
0
文件: async.py 项目: maximon93/pynsq
 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))
示例#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))
示例#5
0
文件: sync.py 项目: maximon93/pynsq
        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))
示例#6
0
文件: sync.py 项目: JustinAzoff/nsq
        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))