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
Distributed Tracing
spakky-tracing은 필수 의존성으로 자동 설치됩니다. ITracePropagator가 컨테이너에 등록되어 있으면 이벤트 발행/소비 시 TraceContext가 자동으로 전파됩니다.
- 발행 측:
IEventTransport.send()시 현재TraceContext를 메시지 헤더에 주입합니다 - 소비 측: 수신 메시지에서
TraceContext를 추출하여 자식 스팬을 생성합니다 - 헤더가 없으면 새로운 루트 트레이스를 시작합니다
Features
- Automatic queue declaration: Durable 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
- Distributed tracing:
spakky-tracingintegration for cross-service trace propagation
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
InvalidMessageError: Raised when a message is missing required metadata (consumer_tagordelivery_tag)
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spakky_rabbitmq-6.4.0.tar.gz.
File metadata
- Download URL: spakky_rabbitmq-6.4.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92ab6eb52c3436034b89254d4eeb574408f872d1d833bdc0914305df09794085
|
|
| MD5 |
1abed82cd25067540ae99051457fbc81
|
|
| BLAKE2b-256 |
834135452af07254d178d68174f35ccbc45f40d31eecb9b245dbf55383f93118
|
Provenance
The following attestation bundles were made for spakky_rabbitmq-6.4.0.tar.gz:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_rabbitmq-6.4.0.tar.gz -
Subject digest:
92ab6eb52c3436034b89254d4eeb574408f872d1d833bdc0914305df09794085 - Sigstore transparency entry: 1435904531
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@9b55f2f729fb6e6397bbf0d1ce584eaec72ffef8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9b55f2f729fb6e6397bbf0d1ce584eaec72ffef8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_rabbitmq-6.4.0-py3-none-any.whl.
File metadata
- Download URL: spakky_rabbitmq-6.4.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c52f0de150bb4ae9fce4b19aefb19a2f38f2101b4e1911d9c98474480505c1
|
|
| MD5 |
4bd9de20b182e4fe73ac935d78f9b1f3
|
|
| BLAKE2b-256 |
cfeac8e5943615226762faba897635dd5e560f7027d58fb4c8d9cca39398909b
|
Provenance
The following attestation bundles were made for spakky_rabbitmq-6.4.0-py3-none-any.whl:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_rabbitmq-6.4.0-py3-none-any.whl -
Subject digest:
e7c52f0de150bb4ae9fce4b19aefb19a2f38f2101b4e1911d9c98474480505c1 - Sigstore transparency entry: 1435904620
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@9b55f2f729fb6e6397bbf0d1ce584eaec72ffef8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9b55f2f729fb6e6397bbf0d1ce584eaec72ffef8 -
Trigger Event:
workflow_dispatch
-
Statement type: