Search code examples
pythonnsqpynsq

pynsq: Reader object has no attribute 'finish'


This error occurs on pynsq 0.4.2

STACKTRACE


2013-07-30 15:03:43,205 ERROR [ip-10-114-195-89:4150:nsq_msg_handler] failed to handle_message() 
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/nsq/Reader.py", line 367, in _data_callback
    self._handle_message(conn, message)
  File "/usr/local/lib/python2.7/dist-packages/nsq/Reader.py", line 291, in _handle_message
    return message.requeue()
  File "/usr/local/lib/python2.7/dist-packages/nsq/nsq.py", line 47, in requeue
    self.respond(REQ, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/nsq/Reader.py", line 211, in _message_responder
    self._requeue(conn, message, time_ms=kwargs.get('time_ms', -1))
  File "/usr/local/lib/python2.7/dist-packages/nsq/Reader.py", line 222, in _requeue
    return self.finish(conn, message)
AttributeError: 'Reader' object has no attribute 'finish'

CODE



    def connect_nsq(self):
        r = nsq.Reader(message_handler=self.nsq_msg_handler, lookupd_http_addresses=["127.0.0.1:4161"], topic="test_topic", channel="test_channel", max_in_flight=500)

        nsq.run()


    # callback
    def nsq_msg_handler(self, message):
        try:
            before_ts = get_utc_now_ts() 
            json_data = json.loads(message.body)

            my_data = json_data["key1"]
            my_data = json_data["key2"]
            my_data = json_data["key3"]

            after_ts = get_utc_now_ts() 
            delta = after_ts - before_ts 
            logger.debug("took %f seconds for json_data _id: %s" % (delta, json_data["_id"])) 
        except Exception as reason:
            print reason, traceback.format_exc()
            return False

       return true


Solution

  • This issue was fixed in the latest release of pynsq which is 0.5.0

    Here's the bug report: https://github.com/bitly/pynsq/issues/44