Created
May 23, 2016 09:00
-
-
Save misja/56b29145cfca35a7fbbc9105c3ea9cca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import nsq | |
import asyncio | |
import tornado | |
import tornado.ioloop | |
import tornado.platform.asyncio | |
queue = asyncio.Queue() | |
async def go(): | |
def enqueue_message(message): | |
message.enable_async() | |
queue.put_nowait(message) | |
reader = nsq.Reader(message_handler=enqueue_message, | |
lookupd_http_addresses=['http://127.0.0.1:4161'], | |
topic='test', channel='async') | |
while True: | |
message = await queue.get() | |
print(message.body) | |
message.finish() | |
queue.task_done() | |
if __name__ == '__main__': | |
tornado.platform.asyncio.AsyncIOMainLoop().install() | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(go()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment