Skip to main content

RabbitMQ plugin for Spakky framework

Project description

Spakky RabbitMQ

RabbitMQ plugin for Spakky Framework.

Installation

pip install spakky-rabbitmq

Or install via Spakky extras:

pip install spakky[rabbitmq]

Configuration

Set environment variables with the SPAKKY_RABBITMQ__ prefix:

export SPAKKY_RABBITMQ__USE_SSL="false"
export SPAKKY_RABBITMQ__HOST="localhost"
export SPAKKY_RABBITMQ__PORT="5672"
export SPAKKY_RABBITMQ__USER="guest"
export SPAKKY_RABBITMQ__PASSWORD="guest"
export SPAKKY_RABBITMQ__EXCHANGE_NAME="my-exchange"  # Optional

Usage

Event Publishing

from spakky.core.common.mutability import immutable
from spakky.domain.models.event import AbstractIntegrationEvent
from spakky.event.event_publisher import IEventPublisher
from spakky.core.pod.annotations.pod import Pod

@immutable
class UserCreatedEvent(AbstractIntegrationEvent):
    user_id: int
    email: str

@Pod()
class UserService:
    def __init__(self, publisher: IEventPublisher) -> None:
        self.publisher = publisher

    def create_user(self, email: str) -> User:
        user = User(email=email)
        self.publisher.publish(UserCreatedEvent(user_id=user.id, email=email))
        return user

Event Consuming

from spakky.event.stereotype.event_handler import EventHandler, on_event

@EventHandler()
class UserEventHandler:
    def __init__(self, notification_service: NotificationService) -> None:
        self.notification_service = notification_service

    @on_event(UserCreatedEvent)
    async def on_user_created(self, event: UserCreatedEvent) -> None:
        await self.notification_service.send_welcome_email(event.email)

Async Variants

For async applications, use IAsyncEventPublisher:

from spakky.event.event_publisher import IAsyncEventPublisher

@Pod()
class AsyncUserService:
    def __init__(self, publisher: IAsyncEventPublisher) -> None:
        self.publisher = publisher

    async def create_user(self, email: str) -> User:
        user = User(email=email)
        await self.publisher.publish(UserCreatedEvent(user_id=user.id, email=email))
        return user

Features

  • Automatic queue declaration: Queues are created based on event type names
  • Sync and Async support: Both synchronous and asynchronous publishers/consumers
  • Background service pattern: Consumer polling runs as a background service
  • Pydantic serialization: Events are serialized/deserialized using Pydantic
  • Exchange routing: Optional exchange for pub/sub message patterns
  • SSL support: Secure connections via AMQPS protocol

Components

Component Description
RabbitMQEventTransport Synchronous event transport (IEventTransport)
AsyncRabbitMQEventTransport Asynchronous event transport (IAsyncEventTransport)
RabbitMQEventConsumer Synchronous event consumer (background service)
AsyncRabbitMQEventConsumer Asynchronous event consumer (background service)
RabbitMQConnectionConfig Configuration via environment variables

Error Handling

  • DuplicateEventHandlerError: Raised when multiple handlers are registered for the same event type
  • InvalidMessageError: Raised when a message is missing required metadata (consumer_tag or delivery_tag)

License

MIT License

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

spakky_rabbitmq-6.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

spakky_rabbitmq-6.0.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file spakky_rabbitmq-6.0.0.tar.gz.

File metadata

  • Download URL: spakky_rabbitmq-6.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spakky_rabbitmq-6.0.0.tar.gz
Algorithm Hash digest
SHA256 1207c7dd3bbfe670a96a331db3bd0939d93c17a4da158492fbbb5478d7505fdd
MD5 658b2c010f472de534f9947ee6411fc0
BLAKE2b-256 94cdc0b4f11d3e2f268747fee65c81b3973339a6dbf9521cc243d516b5fb0cb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_rabbitmq-6.0.0.tar.gz:

Publisher: release.yml on E5presso/spakky-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spakky_rabbitmq-6.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spakky_rabbitmq-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b5424865c826005c05fe51b06aff464ab0e03ca98bec73f9332b3a17d49e16b
MD5 4a042907e0fa72cc8ca8a9f291dfd843
BLAKE2b-256 b25795ffc6558bce00d7307210f1d5dfdb275f89c9e5118fbaedf09b47f5acd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_rabbitmq-6.0.0-py3-none-any.whl:

Publisher: release.yml on E5presso/spakky-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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