Skip to main content

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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_amqp-0.1.2-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file simple_amqp-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for simple_amqp-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d63a61974ddbb1b8616bd617a897803d04247f2d1e5b3c5cd334480afc36de15
MD5 da8f265681fdaede8c16a0747531c2a5
BLAKE2b-256 b67d9bafa41dd333c587c91f3c550c0c34784fb9cfbefa4337b1a3cecba3f12f

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