reconnect_10s.py 392 B

1234567891011121314151617181920
  1. import asyncio
  2. from nats.aio.client import Client as NATS
  3. async def example():
  4. # [begin reconnect_10s]
  5. nc = NATS()
  6. await nc.connect(
  7. servers=["nats://demo.nats.io:4222"],
  8. reconnect_time_wait=10,
  9. )
  10. # Do something with the connection
  11. await nc.close()
  12. # [end reconnect_10s]
  13. loop = asyncio.get_event_loop()
  14. loop.run_until_complete(example())
  15. loop.close()