Skip to main content

High level interfaces for work with RabbitMQ.

Project description

Stack:

Installation

pip install rabbitmq-clients

Usage

Run rabbitMQ on your computer.

Producer

import asyncio
import json

from rabbitmq_clients import RabbitProducer

if __name__ == "__main__":
    producer = RabbitProducer(
        host='localhost',
        login='test',
        password='test',
    )
    data = {"result": True}
    asyncio.run(
        producer.publish(
            json.dumps(data),
            queue_name='test_queue_name',
        )
    )

Consume multiply queues (recommended)

import asyncio

from rabbitmq_clients import RabbitConsumer, QueueDTO
from rabbitmq_clients.core.types import JSON


async def show_decoded_result(result: JSON):
    print(result)


async def show_encoded_result(result: JSON):
    print(result.body)


if __name__ == "__main__":
    consumer = RabbitConsumer(
        host='localhost',
        login='test',
        password='test',
    )
    first_queue = QueueDTO(
        name='decoded_result',
        callback=show_decoded_result,
    )
    second_queue = QueueDTO(
        name='encoded_result',
        callback=show_encoded_result,
        auto_decode=False,
    )
    consumer.add_queue(first_queue)
    consumer.add_queue(second_queue)

    try:
        asyncio.run(consumer.consume_all())
    except KeyboardInterrupt:
        pass

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

rabbitmq_clients-0.1.19.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

rabbitmq_clients-0.1.19-py3-none-any.whl (7.0 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