public
anonymous / gist:4331602
Created

example metrics worker in Python using pynsq

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
import nsq
import json
 
def metrics_write(message):
json_data = json.loads(message)
# iterate over the metrics you want to record and write
# into your downstream metrics system
if any_metrics_failed:
# this will indicate to pynsq that it should re-queue
# the message for you
return False
return True
 
tasks = {"metrics_write": metrics_write}
r = nsq.Reader(tasks, nsqd_tcp_addresses=['127.0.0.1:4150'],
topic="api_requests", channel="metrics")
nsq.run()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.