我尝试了下面的示例(来自此页面):
nc = NATS()
await nc.connect(servers=["nats://demo.nats.io:4222"])
future = asyncio.Future()
async def cb(msg):
nonlocal future
future.set_result(msg)
await nc.subscribe("updates", cb=cb)
await nc.publish("updates", b'All is Well')
await nc.flush()
# Wait for message to come in
msg = await asyncio.wait_for(future, 1)
Run Code Online (Sandbox Code Playgroud)
但这似乎只对接收一条消息有用。我如何订阅并继续接收消息?
我也看过包 example,但它似乎只是玩双方的对话,然后退出。