pyList

Examply Synchronous Python Reader

gistfile1.py

Examply Synchronous Python Reader

import nsq
 
def task1(message):
    print message
    return True
 
def task2(message):
    print message
    return True
 
all_tasks = {"task1": task1, "task2": task2}
r = nsq.Reader(all_tasks, lookupd_http_addresses=['127.0.0.1:4161'], 
        topic="nsq_reader", channel="asdf")
nsq.run()

Example Async Python Client

import nsq
 
buf = []
 
def process_message(message):
    global buf
    message.enable_async()
    buf.append(message)
    if len(buf) >= 3:
        for msg in buf:
            print msg
            msg.finish()
        buf = []
    else:
        print 'deferring processing'
    
all_tasks = {"task1": process_message}
r = nsq.Reader(all_tasks, lookupd_http_addresses=['127.0.0.1:4161'],
        topic="nsq_reader", channel="async", max_in_flight=9)
nsq.run()
本文网址: https://pylist.com/t/1421315809 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
Be the first to comment!
Captcha image
Relative Articles