reconnect_none.py 487 B

123456789101112131415161718192021222324
  1. import asyncio
  2. from nats.aio.client import Client as NATS
  3. async def example():
  4. # [begin reconnect_none]
  5. nc = NATS()
  6. await nc.connect(
  7. servers=[
  8. "nats://demo.nats.io:1222",
  9. "nats://demo.nats.io:1223",
  10. "nats://demo.nats.io:1224"
  11. ],
  12. allow_reconnect=False,
  13. )
  14. # Do something with the connection
  15. await nc.close()
  16. # [end reconnect_none]
  17. loop = asyncio.get_event_loop()
  18. loop.run_until_complete(example())
  19. loop.close()