Skip to main content

aioampq without callbacks!

Project description

Asyncamqp is a little extension to aioamqp based on the ideas from this pull request (https://github.com/Polyconseil/aioamqp/pull/118). The changes here get rid of the callbacks stuff.

Install

Install it using pip

$ pip install asyncamqp

Usage

To publish stuff, just do the same as you would do with aioamqp:

await channel.basic_publish(payload='hi there!', exchange_name='',
                            routing_key='my-rt')

To consume stuff, you don’t need to use callbacks anymore.

async with channel.basic_consume(queue_name='my-queue', exchange_name='',
                                 routing_key='my-queue') as consumer:
    async for msg in consumer:
        print(msg.body)

Consuming messages this way we always wait for a new message to arrive in the queue. We can use a timeout in milliseconds for it, too:

# now we pass the timeout argument
async with channel.basic_consume(queue_name='my-queue', exchange_name='',
                                 routing_key='my-queue',
                                 timeout=100) as consumer:
    async for msg in consumer:
        print(msg.body)

Or we could simply consume the messages already in the queue and stop consuming stuff when we have no more messages:

# now we pass the wait_message argument.
async with channel.basic_consume(queue_name='my-queue', exchange_name='',
                                 routing_key='my-queue',
                                 wait_message=False) as consumer:
    async for msg in consumer:
        print(msg.body)

As it is a simple extension to aioamqp, please refer to the aioamqp’s docs for full information. Just remember that when consuming it you don’t use callbacks but the context manager/async for stuff.

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

asyncamqp-0.1.5.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file asyncamqp-0.1.5.tar.gz.

File metadata

  • Download URL: asyncamqp-0.1.5.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.3

File hashes

Hashes for asyncamqp-0.1.5.tar.gz
Algorithm Hash digest
SHA256 430f9b8de2af51a030d6a9da880fe2ccb52979e40cf73fd4c8b216e47961b4d3
MD5 ca242ed4b1ff1b5a92445a47e5659257
BLAKE2b-256 f01cb96a2838fb2a9e271f6a7e1996cc5a47f4bbc1ecc457d8867ab5ff4b90e1

See more details on using hashes here.

Supported by

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