Skip to main content

aio-easy-rabbit

An opinionated way to use RabbitMQ in Asyncio based frameworks.

Installation

to be continued ...

Usage example

Simple consumer example in a FastAPI

from fastapi import FastAPI
from aio_easy_rabbit.connection import (
    connect_to_rabbitmq,
    start_listening_to_queue,
)


app = FastAPI()

@rabbitmq_consumer("test_queue")
async def test_consumer(message):
    print(message)


@app.on_event("startup")
async def startup_event():
    registry = ConsumerRegistry()
    rabbitmq_connection_string = "amqp://guest:guest@localhost"
    app.state.rabbitmq_connection = await connect_to_rabbitmq(
        rabbitmq_connection_string
    )
    for queue_name in registry.get_registered_queues():
        asyncio.create_task(
            start_listening_to_queue(app.state.rabbitmq_connection, queue_name)
        )

Key component is the ConsumerRegistry that will manage state of all registered queues and their consuming functions.

Note: Each decorated consumer will receive a raw string that needs to be serialized as pleased.

Simple publisher example in FastAPI

from fastapi import FastAPI

from aio_easy_rabbit.connection import (
    connect_to_rabbitmq
)
from aio_easy_rabbit.producers import RabbitMQPublisher

app = FastAPI()


class Message(BaseModel):
    message: str


@app.post("/test/{queue_name}/")
async def test_endpoint(queue_name: str, message: Message):
    await app.state.rabbitmq_publisher.publish_message(queue_name, message)
    return {"message": "Message published"}


@app.on_event("startup")
async def startup_event():
    rabbitmq_connection_string = "amqp://guest:guest@localhost"
    app.state.rabbitmq_connection = await connect_to_rabbitmq(
        rabbitmq_connection_string
    )
    app.state.rabbitmq_publisher = RabbitMQPublisher(rabbitmq_connection_string)

Metadata

Release files for aio-easy-rabbit 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aio-easy-rabbit 0.0.1
File Size Uploaded
aio-easy-rabbit-0.0.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aio-easy-rabbit 0.0.1
File Interpreter ABI Platform
aio_easy_rabbit-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / aio-easy-rabbit-0.0.1.tar.gz

Download URL aio-easy-rabbit-0.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b4a1fcaff12690948069dabf5d956ef0401c3225db2605d96c0c3f0464e25fc5
BLAKE2b-256 checksum
How to use checksums
f9babb8f25e66d2c136644aa91ffd00ba9d6d432284a0246b561860da45aa179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / aio_easy_rabbit-0.0.1-py3-none-any.whl

Download URL aio_easy_rabbit-0.0.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
080d12e6a9fa9693703d92c8b719576f3d622a5403d54b445da45548492680f5
BLAKE2b-256 checksum
How to use checksums
19b0b46bf2ef70702cc5a2bce7ae5919af3408633757d733dd7c34867ef44fb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page