pynsq: backing off for 'n' seconds

234 Views Asked by At

WHAT I am consuming messages from a NSQ server using 4 consumers. I am trying to debug the reason why I see the backing off logs as my consumers slow down when this happens.

I am logging exceptions and that's when I return a False to requeue the message. I don't see any exceptions being logged but I keep seeing this message. Help!!


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

There are 1 best solutions below

0
On

Looks like the problem is your very last line True should be capitalized. They reason your traceback is not printed is because the exception occurs outside of your try block.