spakky-event¶
인프로세스 이벤트 시스템 — EventBus, EventTransport, EventMediator
Publisher Interfaces¶
spakky.event.event_publisher
¶
Event publishing and transport interfaces.
Provides publisher, bus, and transport abstractions for event routing: - IEventPublisher: Routes events by type (domain vs integration). - IEventBus: Serializes and sends integration events via transport. - IEventTransport: Low-level transport for serialized event payloads.
IEventPublisher
¶
Bases: ABC
Publishes events by routing to dispatcher or bus based on event type.
publish(event)
abstractmethod
¶
IAsyncEventPublisher
¶
Bases: ABC
Async counterpart of IEventPublisher.
IEventBus
¶
IAsyncEventBus
¶
Bases: ABC
Asynchronous event bus for sending integration events.
send(event)
abstractmethod
async
¶
IEventTransport
¶
Bases: ABC
Low-level synchronous transport for pre-serialized event payloads.
send(event_name, payload)
abstractmethod
¶
options: show_root_heading: false
Consumer Interfaces¶
spakky.event.event_consumer
¶
Event consumer interfaces for registering event handlers.
EventHandlerCallback = Callable[[EventT_contra], None]
module-attribute
¶
Synchronous event handler callback type.
AsyncEventHandlerCallback = Callable[[EventT_contra], Awaitable[None]]
module-attribute
¶
Asynchronous event handler callback type.
IEventConsumer
¶
Bases: ABC
Synchronous event consumer interface for registering event handlers.
register(event, handler)
abstractmethod
¶
Register a handler callback for the given event type.
options: show_root_heading: false
Dispatcher Interfaces¶
spakky.event.event_dispatcher
¶
Event dispatcher interfaces for dispatching events to registered handlers.
This module provides unified dispatcher interfaces that handle all event types. Dispatchers are responsible for delivering events to registered handlers, while Consumers are responsible for handler registration. These interfaces are combined in Mediator implementations.
options: show_root_heading: false
Event Bus¶
spakky.event.bus.transport_event_bus
¶
Default EventBus implementations that delegate to EventTransport.
DirectEventBus(transport)
¶
Bases: IEventBus
Synchronous event bus that serializes and delegates to IEventTransport.
Initialize with the given transport.
Source code in core/spakky-event/src/spakky/event/bus/transport_event_bus.py
send(event)
¶
Serialize and send an integration event via transport.
Source code in core/spakky-event/src/spakky/event/bus/transport_event_bus.py
AsyncDirectEventBus(transport)
¶
Bases: IAsyncEventBus
Asynchronous event bus that serializes and delegates to IAsyncEventTransport.
Initialize with the given async transport.
Source code in core/spakky-event/src/spakky/event/bus/transport_event_bus.py
send(event)
async
¶
Serialize and send an integration event via async transport.
Source code in core/spakky-event/src/spakky/event/bus/transport_event_bus.py
options: show_root_heading: false
Mediator¶
spakky.event.mediator.domain_event_mediator
¶
Event mediator implementations.
This module provides in-process mediator implementations that combine Consumer and Dispatcher interfaces. Mediators manage handler registration and event dispatching within the same bounded context.
EventMediator()
¶
Bases: IEventConsumer, IEventDispatcher
In-process synchronous event mediator combining consumer and dispatcher roles.
Initialize an empty handler registry.
Source code in core/spakky-event/src/spakky/event/mediator/domain_event_mediator.py
register(event, handler)
¶
Register a handler callback for the given event type.
Source code in core/spakky-event/src/spakky/event/mediator/domain_event_mediator.py
dispatch(event)
¶
Dispatch an event to all registered handlers.
Source code in core/spakky-event/src/spakky/event/mediator/domain_event_mediator.py
AsyncEventMediator()
¶
Bases: IAsyncEventConsumer, IAsyncEventDispatcher
In-process asynchronous event mediator combining consumer and dispatcher roles.
Initialize an empty async handler registry.
Source code in core/spakky-event/src/spakky/event/mediator/domain_event_mediator.py
register(event, handler)
¶
Register an async handler callback for the given event type.
Source code in core/spakky-event/src/spakky/event/mediator/domain_event_mediator.py
dispatch(event)
async
¶
Dispatch an event to all registered async handlers.
Source code in core/spakky-event/src/spakky/event/mediator/domain_event_mediator.py
options: show_root_heading: false
Publisher¶
spakky.event.publisher.domain_event_publisher
¶
Event publisher implementations.
This module provides event publishers that route events by type: - AbstractDomainEvent → EventMediator (in-process dispatch) - AbstractIntegrationEvent → IEventBus (external transport)
EventPublisher(dispatcher, bus)
¶
Bases: IEventPublisher
Routes events by type: domain events to dispatcher, integration events to bus.
Initialize with dispatcher and bus dependencies.
Source code in core/spakky-event/src/spakky/event/publisher/domain_event_publisher.py
publish(event)
¶
Route an event to the appropriate handler based on its type.
Source code in core/spakky-event/src/spakky/event/publisher/domain_event_publisher.py
AsyncEventPublisher(dispatcher, bus)
¶
Bases: IAsyncEventPublisher
Async counterpart that routes events by type.
Initialize with async dispatcher and bus dependencies.
Source code in core/spakky-event/src/spakky/event/publisher/domain_event_publisher.py
publish(event)
async
¶
Route an event to the appropriate async handler based on its type.
Source code in core/spakky-event/src/spakky/event/publisher/domain_event_publisher.py
options: show_root_heading: false
Aspects¶
spakky.event.aspects.transactional_event_publishing
¶
Transactional event publishing aspect for automatic domain event publishing.
AsyncTransactionalEventPublishingAspect(collector, publisher)
¶
Bases: IAsyncAspect
Source code in core/spakky-event/src/spakky/event/aspects/transactional_event_publishing.py
after_returning_async(result)
async
¶
Publish domain events from collected aggregates after successful commit.
Source code in core/spakky-event/src/spakky/event/aspects/transactional_event_publishing.py
after_async()
async
¶
Clear the aggregate collector after transaction completion.
TransactionalEventPublishingAspect(collector, publisher)
¶
Bases: IAspect
Source code in core/spakky-event/src/spakky/event/aspects/transactional_event_publishing.py
after_returning(result)
¶
Publish domain events from collected aggregates after successful commit.
Source code in core/spakky-event/src/spakky/event/aspects/transactional_event_publishing.py
after()
¶
Clear the aggregate collector after transaction completion.
options: show_root_heading: false
Stereotype¶
spakky.event.stereotype.event_handler
¶
EventHandler stereotype and event routing decorators.
This module provides @EventHandler stereotype and @on_event decorator for organizing event-driven architectures.
EventT_contra = TypeVar('EventT_contra', bound=AbstractEvent, contravariant=True)
module-attribute
¶
Type variable for domain event types (contravariant for handler parameters).
EventHandlerMethod = Callable[[Any, EventT_contra], None | Awaitable[None]]
module-attribute
¶
Type alias for event handler callback functions.
EventRoute(event_type)
dataclass
¶
Bases: FunctionAnnotation, Generic[EventT_contra]
Annotation for marking methods as event handlers.
Associates a method with a specific domain event type.
event_type
instance-attribute
¶
The domain event type this handler processes.
__call__(obj)
¶
Apply event route annotation to method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
EventHandlerMethod[EventT_contra]
|
The method to annotate. |
required |
Returns:
| Type | Description |
|---|---|
EventHandlerMethod[EventT_contra]
|
The annotated method. |
Source code in core/spakky-event/src/spakky/event/stereotype/event_handler.py
EventHandler(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for event handler classes.
EventHandlers contain methods decorated with @on_event that process domain events asynchronously.
on_event(event_type)
¶
Decorator for marking methods as event handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
type[EventT_contra]
|
The domain event type to handle. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[EventHandlerMethod[EventT_contra]], EventHandlerMethod[EventT_contra]]
|
Decorator function that applies EventRoute annotation. |
Example
@EventHandler() class UserEventHandler: @on_event(UserCreatedEvent) async def handle_user_created(self, event: UserCreatedEvent) -> None: # Handle event pass
Source code in core/spakky-event/src/spakky/event/stereotype/event_handler.py
options: show_root_heading: false
Post Processor¶
spakky.event.post_processor
¶
Event handler registration post-processor.
EventHandlerRegistrationPostProcessor
¶
Bases: IPostProcessor, IContainerAware
Scans @EventHandler Pods and registers their @on_event methods with consumers.
set_container(container)
¶
post_process(pod)
¶
Register event handler methods with the appropriate consumer.
Source code in core/spakky-event/src/spakky/event/post_processor.py
options: show_root_heading: false
Errors¶
spakky.event.error
¶
options: show_root_heading: false