Skip to main content

Python AMQP Client Library

Reason this release was yanked:

deprecated

Project description

AMQP Client Python

License Package version Supported Python versions Downloads Vulnerabilities Releases


Client with high level of abstraction for manipulation of messages in the event bus RabbitMQ.

Features:

  • Automatic creation and management of queues, exchanges and channels;
  • Connection persistence and auto reconnect;
  • Support for direct, topic and fanout exchanges;
  • Publish;
  • Subscribe;
  • Support for a Remote procedure call (RPC).

Examples:

you can use sync and async eventbus

async usage
# basic configuration
from amqp_client_python import (
    AsyncEventbusRabbitMQ,
    Config, Options
)
from amqp_client_python.event import IntegrationEvent, IntegrationEventHandler
config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
eventbus = AsyncEventbusRabbitMQ(config)
# publish
class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message

publish_event = ExampleEvent(rpc_exchange, ["message"])
eventbus.publish(publish_event, rpc_routing_key, "direct")
# subscribe
class ExampleEventHandler(IntegrationEventHandler):
    def handle(self, body) -> None:
        print(body) # handle messages
await eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)
# rpc_publish
response = await eventbus.rpc_client(rpc_exchange, "user.find", ["content_message"])
# provider
async def handle2(*body) -> bytes:
    print(f"body: {body}")
    return b"content"
await eventbus.provide_resource("user.find", handle)
sync usage
from amqp_client_python import (
    EventbusRabbitMQ,
    Config, Options
)
from amqp_client_python.event import IntegrationEvent, IntegrationEventHandler
from examples.default import queue, rpc_queue, rpc_exchange, rpc_routing_key


class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    ROUTING_KEY: str = rpc_routing_key

    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message
        self.routing_key = self.ROUTING_KEY


class ExampleEventHandler(IntegrationEventHandler):
    def handle(self, body) -> None:
        print(body,"subscribe")


config = Config(Options(queue, rpc_queue, rpc_exchange))
eventbus = EventbusRabbitMQ(config=config)

class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message

from time import sleep
from random import randint
def handle(*body):
    print(body[0], "rpc_provider")
    return f"{body[0]}".encode("utf-8")

subscribe_event = ExampleEvent(rpc_exchange)
publish_event = ExampleEvent(rpc_exchange, ["message"])
subscribe_event_handle = ExampleEventHandler()
eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)
eventbus.provide_resource(rpc_routing_key+"2", handle)
count = 0
running = True
from concurrent.futures import TimeoutError
while running:
    try:
        count += 1
        if str(count) != eventbus.rpc_client(rpc_exchange, rpc_routing_key+"2", [f"{count}"]).decode("utf-8"):
            running = False
        #eventbus.publish(publish_event, rpc_routing_key, "direct")
        #running = False
    except TimeoutError as err:
        print("timeout!!!: ", str(err))
    except KeyboardInterrupt:
        running=False
    except BaseException as err:
        print("Err:", err)

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

amqp_client_python-0.0.5.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

amqp_client_python-0.0.5-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file amqp_client_python-0.0.5.tar.gz.

File metadata

  • Download URL: amqp_client_python-0.0.5.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-58-generic

File hashes

Hashes for amqp_client_python-0.0.5.tar.gz
Algorithm Hash digest
SHA256 85e2496c6b2180f45445bc2632d5c53228b41c1f1c7211e31e3192b8e6e328ab
MD5 47e2d4834aeaeb86725495c90d5e0daf
BLAKE2b-256 f94ef815760e234accce0c7408c5bdef046a536b9182310ab7ac1cdbb8715423

See more details on using hashes here.

File details

Details for the file amqp_client_python-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: amqp_client_python-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-58-generic

File hashes

Hashes for amqp_client_python-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ac87b18f99849bc8ed98966355eece19c3aad0374a4ce8457c2ee3fac23edbde
MD5 b1a2d42b7f45c275b633623e0fe9cf8e
BLAKE2b-256 5af46a4e2c5cc8aaa655d0a2d886f1b101dd272e45763e8d6275df8a2c3cefbe

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