Created
April 14, 2016 17:18
-
-
Save marshyski/842ed1e826bc7fb21ca87ae97783bbcc to your computer and use it in GitHub Desktop.
pynsq JSON example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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