connect_multiple.py 426 B

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