Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pynsq example for connecting to Bitly Datastream
import json
import logging
import nsq
import sys
import tornado
import tornado.options
def handle_message(message):
print json.loads(message.body)['u']
message.finish()
if __name__ == "__main__":
tornado.options.define("access_token", type=str)
tornado.options.define("topic", type=str)
tornado.options.define("channel", type=str)
tornado.options.parse_command_line()
logging.info('pynsq:%s tornado:%s python:%s', nsq.version.__version__, tornado.version, sys.version)
lookup = "https://api-ssl.bitly.com/v3/nsq/lookup?access_token=%s" % tornado.options.options.access_token
r = nsq.Reader(message_handler=handle_message,
lookupd_http_addresses=[lookup],
auth_secret=tornado.options.options.access_token,
tls_v1=True,
max_in_flight=1000,
topic=tornado.options.options.topic,
channel=tornado.options.options.channel
)
nsq.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.