connect_url.py 343 B

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