Created
August 23, 2014 14:07
-
-
Save jehiah/49f66d8be24439e66950 to your computer and use it in GitHub Desktop.
Example NSQ Reader
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
""" | |
Usage: | |
./reader.py --nsqd-tcp-address=address:port --topic=topic --channel=channel | |
""" | |
import nsq | |
import tornado.options | |
def handler(message): | |
print message.body, message.attempts | |
message.finish() | |
def run(): | |
r = nsq.Reader(message_handler=handler, | |
nsqd_tcp_addresses=[tornado.options.options.nsqd_tcp_address], | |
topic=tornado.options.options.topic, | |
channel=tornado.options.options.channel, | |
) | |
nsq.run() | |
if __name__ == "__main__": | |
tornado.options.define("nsqd_tcp_address", type=str, help="the destination NSQd address:port") | |
tornado.options.define("topic", type=str, help="the NSQ Topic to consume from") | |
tornado.options.define("channel", type=str, help="the NSQ Channel to consume from") | |
tornado.options.parse_command_line() | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment