A python client for RabbitMQ Streams
Project description
RabbitMQ Stream Python Client
A Python asyncio-based client for RabbitMQ Streams
This is a work in progress
Install
pip install rstream
Quick start
Publishing messages:
import asyncio
from rstream import Producer
async def publish():
async with Producer('localhost', username='guest', password='guest') as producer:
await producer.create_stream('mystream')
for i in range(100):
await producer.publish('mystream', f'msg: {i}'.encode())
asyncio.run(publish())
Consuming messages:
import asyncio
import signal
from rstream import Consumer
async def consume():
consumer = Consumer(
host='localhost',
port=5552,
vhost='/',
username='guest',
password='guest',
)
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGINT, lambda: asyncio.create_task(consumer.close()))
def on_message(msg):
print('Got message:', msg)
await consumer.start()
await consumer.subscribe('mystream', on_message)
await consumer.run()
asyncio.run(consume())
TODO
- Documentation
- Handle
MetadataUpdate
and reconnect to another broker on stream configuration changes - AsyncIterator protocol for consumer
- Add frame size validation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rstream-0.3.0.tar.gz
(14.0 kB
view hashes)
Built Distribution
rstream-0.3.0-py3-none-any.whl
(16.9 kB
view hashes)