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

Install

pip install rstream

Quick start

Publishing messages:

import asyncio
from rstream import Producer, AMQPMessage

async def publish():
    async with Producer('localhost', username='guest', password='guest') as producer:
        await producer.create_stream('mystream')

        for i in range(100):
            amqp_message = AMQPMessage(
                body='hello: {}'.format(i),
            )
            await producer.publish('mystream', amqp_message)

asyncio.run(publish())

Consuming messages:

import asyncio
import signal
from rstream import Consumer, amqp_decoder, AMQPMessage

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: AMQPMessage):
        print('Got message: {}'.format(msg.body))

    await consumer.start()
    await consumer.subscribe('mystream', on_message, decoder=amqp_decoder)
    await consumer.run()

asyncio.run(consume())

Connecting with SSL:

import ssl

ssl_context = ssl.SSLContext()
ssl_context.load_cert_chain('/path/to/certificate.pem', '/path/to/key.pem')

producer = Producer(
    host='localhost',
    port=5551,
    ssl_context=ssl_context,
    username='guest',
    password='guest',
)

TODO

  • Documentation
  • Handle MetadataUpdate and reconnect to another broker on stream configuration changes
  • AsyncIterator protocol for consumer
  • Add frame size validation

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.4.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

rstream-0.4.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file rstream-0.4.0.tar.gz.

File metadata

  • Download URL: rstream-0.4.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.5 Linux/5.11.0-49-generic

File hashes

Hashes for rstream-0.4.0.tar.gz
Algorithm Hash digest
SHA256 25c1cfda1e995d2943ae3b0c8eb9d48e880ba1d678430e118362a8d763292c30
MD5 486f45b80cb046f4318585fb6e530595
BLAKE2b-256 13a86273fe6ab7777d19e217fa6e62b1c3884c26c051a545002ac180bced2261

See more details on using hashes here.

File details

Details for the file rstream-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: rstream-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.5 Linux/5.11.0-49-generic

File hashes

Hashes for rstream-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edb35895108819ea8459bf59b7115471872281eecfd98603f0a200879abccaad
MD5 361a30b95d5ecdfe711f5dde8aad0cc7
BLAKE2b-256 dcfc3e5ceea4e36bbcd40cadde3dc6450fa5c6e156fa97f12f3468ca203c4451

See more details on using hashes here.

Supported by

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