nats_produce.py 532 B

12345678910111213141516171819202122
  1. import time
  2. from pynats import NATSClient
  3. from data_develop import develop_random_data
  4. from config import (
  5. index_begin,
  6. index_end,
  7. nats_subject,
  8. nats_url
  9. )
  10. with NATSClient(url=nats_url) as client:
  11. client.connect()
  12. for i in range(index_begin, index_end):
  13. client.publish(
  14. subject=nats_subject,
  15. payload=develop_random_data(i)
  16. )
  17. time.sleep(0.02)
  18. print(f'Sent Index: ', i)
  19. print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')