
As this now has an AsyncContext, producer.close() & consumer.close() is called automatically when exiting the context.
28 lines
642 B
Python
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())
|