我想要的只是在线程中运行ioloop,并将消息写入nsqd。下面是一个尝试:
#!/usr/bin/env python2
# coding=utf-8
import tornado
import time
from nsq.writer import Writer
w = Writer(["bj1:4150", "bj2:4150"], reconnect_interval=15)
w.connect()
@tornado.gen.coroutine
def future_pub(topic, msg):
result = w.pub(topic, msg)
print(result)
time.sleep(3)
raise tornado.gen.Return(result)
@tornado.gen.coroutine
def main():
while True:
try:
future = future_pub("test", "message")
yield future
except Exception as e:
print(e.message)
tornado.ioloop.IOLoop.instance().run_sync(main)但它并没有起作用。你能帮我一下吗?谢谢!
发布于 2016-03-29 22:43:51
您从未运行过nsq.run(),因此没有打开任何连接,并且您的Writer无法发布消息。
请参阅文档中的示例:https://pynsq.readthedocs.org/en/latest/writer.html,它使用PeriodicCallback每秒发送一次消息。
https://stackoverflow.com/questions/36264629
复制相似问题