flush.py 523 B

1234567891011121314151617181920212223
  1. import asyncio
  2. from nats.aio.client import Client as NATS
  3. async def example():
  4. # [begin flush]
  5. nc = NATS()
  6. await nc.connect(servers=["nats://demo.nats.io:4222"])
  7. await nc.publish("updates", b'All is Well')
  8. # Sends a PING and wait for a PONG from the server, up to the given timeout.
  9. # This gives guarantee that the server has processed above message.
  10. await nc.flush(timeout=1)
  11. # [end flush]
  12. await nc.close()
  13. loop = asyncio.get_event_loop()
  14. loop.run_until_complete(example())
  15. loop.close()