nats_consume_async.py 597 B

12345678910111213141516171819202122232425262728
  1. import nats
  2. import asyncio
  3. from time import sleep
  4. from nats_produce_async import develop_publish
  5. from data_develop import develop_callback_async
  6. from config import (
  7. nats_url,
  8. nats_subject
  9. )
  10. async def main(loop):
  11. nc = await nats.connect(nats_url)
  12. sub = await nc.subscribe(
  13. nats_subject,
  14. cb=develop_callback_async
  15. )
  16. await sub.unsubscribe(limit=3000000)
  17. await develop_publish(nc)
  18. await nc.drain()
  19. if __name__ == '__main__':
  20. loop = asyncio.get_event_loop()
  21. loop.run_until_complete(main(loop))
  22. # loop.run_forever()
  23. loop.close()