produce.py 289 B

123456789101112131415
  1. import asyncio
  2. import pydantic
  3. class Foo(pydantic.BaseModel):
  4. foo: str
  5. async def producer(app, topic):
  6. while True:
  7. try:
  8. await app.publish(topic, Foo(foo="bar"))
  9. await asyncio.sleep(0.05)
  10. except asyncio.CancelledError:
  11. return