Skip to main content

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

Quick start

Publishing messages:

from rstream import Producer, Consumer

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())

Consuming messages:

async with Consumer('localhost', username='guest', password='guest') as consumer:
    async for msg in consumer.iterator('mystream'):
        print('Got message:', msg)

        if msg.endswith(b'99'):
            break

Or with a callback function:

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()

Project details


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.1.1.tar.gz (13.1 kB view hashes)

Uploaded Source

Built Distribution

rstream-0.1.1-py3-none-any.whl (16.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page