Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Simple AMQP lib

Project description

Simple AMQP

A simple AMQP lib for Python

Installation

# Asyncio
pip install simple-amqp[asyncio]

# Gevent
pip install simple-amqp[gevent]

Example usage

# Asyncio
from asyncio import get_event_loop, sleep

from simple_amqp import AmqpMsg, AmqpParameters
from simple_amqp.asyncio import AsyncioAmqpConnection

conn = AsyncioAmqpConnection(AmqpParameters(host='localhost'))
channel = conn.channel()

exchange = channel.exchange('exchange.name', 'topic', durable=True)


async def msg_received(msg: AmqpMsg):
    if msg.payload == b'ok':
        return True # ack msg

    return False # nack msg


channel \
  .queue('queue.name', durable=True) \
  .bind(exchange, 'topic.name') \
  .consume(msg_received)


async def main():
    await conn.start()
    await channel.publish(AmqpMsg(
        exchange='exchange.name',
        topic='topic.name',
        payload=b'ok',
    ))

    await sleep(1)
    await conn.stop()

loop = get_event_loop()
loop.run_until_complete(main)
# Gevent
from gevent import monkey
monkey.patch_all()

from time import sleep

from simple_amqp import AmqpMsg, AmqpParameters
from simple_amqp.gevent import GeventAmqpConnection

conn = GeventAmqpConnection(AmqpParameters(host='localhost'))
channel = conn.channel()

exchange = channel.exchange('exchange.name', 'topic', durable=True)


def msg_received(msg: AmqpMsg):
    if msg.payload == b'ok':
        return True # ack msg

    return False # nack msg


channel \
  .queue('queue.name', durable=True) \
  .bind(exchange, 'topic.name') \
  .consume(msg_received)

conn.start()

channel.publish(AmqpMsg(
    exchange='exchange.name',
    topic='topic.name',
    payload=b'ok',
))

sleep(1)
conn.stop()

Project details


Download files

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

Files for simple-amqp, version 0.2.6
Filename, size File type Python version Upload date Hashes
Filename, size simple_amqp-0.2.6-py2.py3-none-any.whl (11.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes

Supported by

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