Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Consumer/producer like library built over amqp (aioamqp)

Project description

info:Consumer/producer like library built over amqp (aioamqp)

Installation

pip install aioamqp_consumer

Usage

import asyncio
from functools import partial

from aioamqp_consumer import Consumer, Producer


async def task(payload, options, sleep=0, *, loop):
    await asyncio.sleep(sleep, loop=loop)
    print(payload)


async def main(*, loop):
    amqp_url = 'amqp://guest:guest@127.0.0.1:5672//'
    amqp_queue = 'your-queue-here'
    queue_kwargs = {
        'durable': True,
    }
    amqp_kwargs = {}  # https://aioamqp.readthedocs.io/en/latest/api.html#aioamqp.connect

    async with Producer(amqp_url, amqp_kwargs=amqp_kwargs, loop=loop) as producer:
        for _ in range(5):
            await producer.publish(
                b'hello',
                amqp_queue,
                queue_kwargs=queue_kwargs,
            )

    consumer = Consumer(
        amqp_url,
        partial(task, loop=loop, sleep=1),
        amqp_queue,
        queue_kwargs=queue_kwargs,
        amqp_kwargs=amqp_kwargs,
        loop=loop,
    )
    await consumer.scale(20)  # scale up to 20 background coroutines
    await consumer.scale(5)  # downscale to 5 background coroutines
    await consumer.join()  # wait for rabbitmq queue is empty and all local messages are processed
    consumer.close()
    await consumer.wait_closed()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop=loop))
loop.close()

Project details


Release history Release notifications

This version
History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aioamqp_consumer-0.1.2.tar.gz (8.3 kB) Copy SHA256 hash SHA256 Source None Nov 22, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page