Skip to content

Instantly share code, notes, and snippets.

@marshyski
Created April 14, 2016 17:18
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 marshyski/842ed1e826bc7fb21ca87ae97783bbcc to your computer and use it in GitHub Desktop.
Save marshyski/842ed1e826bc7fb21ca87ae97783bbcc to your computer and use it in GitHub Desktop.
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