rabbitmq-tutorials/python-stream/send.py
Cameron Moore-Carter 92134198a7 removed redundant producer.close() calls
As this now has an AsyncContext, producer.close() & consumer.close() is called automatically when exiting the context.
2024-08-05 16:17:13 +12:00

28 lines
642 B
Python

import asyncio
from rstream import Producer
STREAM_NAME = "hello-python-stream"
# 5GB
STREAM_RETENTION = 5000000000
async def send():
async with Producer(
host="localhost",
username="guest",
password="guest",
) as producer:
await producer.create_stream(
STREAM_NAME, exists_ok=True, arguments={"max-length-bytes": STREAM_RETENTION}
)
await producer.send(stream=STREAM_NAME, message=b"Hello, World!")
print(" [x] Hello, World! message sent")
input(" [x] Press Enter to close the producer ...")
with asyncio.Runner() as runner:
runner.run(send())