connect_userpass_url.py 380 B

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