Skip to content

evmyzgin/asynqp

 
 

Repository files navigation

asynqp

Build Status Documentation Status Coverage Status Requirements Status

asynqp is an AMQP (aka RabbitMQ) client library for >=Python 3.5.

Check out the official documentation.

Example

import asyncio
import asynqp


async def hello_world():
    """
    Sends a 'hello world' message and then reads it from the queue.
    """
    # connect to the RabbitMQ broker
    connection = await asynqp.connect('localhost', 5672, username='guest', password='guest')

    # Open a communications channel
    channel = await connection.open_channel()

    # Create a queue and an exchange on the broker
    exchange = await channel.declare_exchange('test.exchange', 'direct')
    queue = await channel.declare_queue('test.queue')

    # Bind the queue to the exchange, so the queue will get messages published to the exchange
    await queue.bind(exchange, 'routing.key')

    # If you pass in a dict it will be automatically converted to JSON
    msg = asynqp.Message({'hello': 'world'})
    exchange.publish(msg, 'routing.key')

    # Synchronously get a message from the queue
    received_message = await queue.get()
    print(received_message.json())  # get JSON from incoming messages easily

    # Acknowledge a delivered message
    received_message.ack()

    await channel.close()
    await connection.close()


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(hello_world())

Installation

asynqp is on the Cheese Shop, so you can install it using Pip:

pip install asynqp

If you want the latest development version, you can install it from source:

git clone https://github.com/benjamin-hodgson/asynqp.git
cd asynqp
python setup.py install

About

An AMQP library for asyncio

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%