pynsq:后退'n'秒

时间:2013-07-30 15:54:59

标签: python nsq pynsq

什么 我正在使用4个消费者从NSQ服务器消费消息。我正在尝试调试我看到backing off日志的原因,因为当发生这种情况时我的消费者会变慢。

我正在记录异常,那是当我返回False以重新排队消息时。我没有看到任何异常被记录,但我一直看到这条消息。帮助!


2013-07-30 14:41:10,304 INFO [ip-10-114-195-89:4150:nsq_msg_handler] backing off for 3.58 seconds
2013-07-30 14:41:10,304 DEBUG took 0.000000 seconds for json_data _id: 52d730669c615b67

2013-07-30 14:46:44,414 INFO [ip-10-114-195-89:4150:nsq_msg_handler] backing off for 3.58 seconds
2013-07-30 14:46:44,414 DEBUG took 0.000000 seconds for json_data _id: 7e9c5fe5ba168496

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

1 个答案:

答案 0 :(得分:1)

看起来问题是你的最后一行True应该大写。他们认为不打印回溯是因为异常发生在try块之外。