Skip to content

Instantly share code, notes, and snippets.

@marshyski
Created Apr 14, 2016
Embed
What would you like to do?
pynsq JSON example
## curl -d '{"test":"data","friend":"tim"}' 'http://127.0.0.1:4151/put?topic=test'
import nsq
import json
buf = []
def process_message(message):
global buf
message.enable_async()
msg = json.loads(message.body)
print msg['friend']
print msg['test']
buf.append(message)
if len(buf) >= 3:
for msg in buf:
print msg.body
msg.finish()
buf = []
else:
print 'deferring processing'
r = nsq.Reader(message_handler=process_message,
lookupd_http_addresses=['http://127.0.0.1:4161'],
topic='test', channel='test', max_in_flight=9)
nsq.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment