避免pynsq中的消息超时

2024-06-01 08:19:59 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,我通过发出以下命令向NSQ发送消息:

curl -d "test2" http://127.0.0.1:4151/pub?topic=hello

我发现,如果消息处理程序的执行时间超过100秒,它将抛出,并且此消息将超时。在

^{pr2}$

如何避免超时?在

这是我的代码:

def process_message(message):
    print(message)
    time.sleep(100)
    message.touch()
    return True

r_check = nsq.Reader(
     message_handler=process_message,
    nsqd_tcp_addresses=['127.0.0.1:4150'],
    topic='hello', channel='channel',
    lookupd_poll_interval=15,
    lookupd_connect_timeout=100000,
    lookupd_request_timeout=100000,
    max_tries=10
)

nsq.run()

谢谢。在


Tags: 命令http消息messagehellotopictimeoutchannel
1条回答
网友
1楼 · 发布于 2024-06-01 08:19:59

您应该在处理消息之前调用message.touch(),以便告诉NSQD您需要更多的时间来处理该消息。在

NSQD中有两个参数控制消息超时:max-msg-timeout and msg-timeout。在

Matt Reiferson解释了它们是如何工作的。在

相关问题 更多 >