Skip to content

Instantly share code, notes, and snippets.

@mreiferson
Last active October 11, 2015 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mreiferson/3925092 to your computer and use it in GitHub Desktop.
Save mreiferson/3925092 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment