spakky-rabbitmq¶
RabbitMQ 통합 — 이벤트 전송/수신
Main¶
spakky.plugins.rabbitmq.main
¶
Plugin initialization for RabbitMQ integration.
Registers event consumers, transports, and post-processors for automatic event handler registration in RabbitMQ-enabled applications.
initialize(app)
¶
Initialize the RabbitMQ plugin.
Registers event consumers, transports, and the post-processor for automatic event handler registration. This function is called automatically by the Spakky framework during plugin loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
SpakkyApplication
|
The Spakky application instance. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/main.py
options: show_root_heading: false
Event Transport¶
spakky.plugins.rabbitmq.event.transport
¶
RabbitMQ event transports for integration events.
Provides synchronous and asynchronous event transports that send integration events to RabbitMQ queues with optional exchange routing.
RabbitMQEventTransport(config)
¶
Bases: IEventTransport
Synchronous RabbitMQ event transport.
Sends pre-serialized event payloads to RabbitMQ queues using blocking connections. Optionally routes through an exchange for pub/sub patterns.
Attributes:
| Name | Type | Description |
|---|---|---|
connection_string |
str
|
AMQP connection string. |
exchange_name |
str | None
|
Optional exchange name for routing. |
Initialize the synchronous RabbitMQ event transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RabbitMQConnectionConfig
|
RabbitMQ connection configuration. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/transport.py
send(event_name, payload)
¶
Send a pre-serialized event payload to RabbitMQ.
Creates a new connection, sends the payload to the appropriate queue, and closes the connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Routing key / queue name for the event. |
required |
payload
|
bytes
|
Pre-serialized JSON bytes. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/transport.py
AsyncRabbitMQEventTransport(config)
¶
Bases: IAsyncEventTransport
Asynchronous RabbitMQ event transport.
Sends pre-serialized event payloads to RabbitMQ queues using async connections. Optionally routes through an exchange for pub/sub patterns.
Attributes:
| Name | Type | Description |
|---|---|---|
connection_string |
str
|
AMQP connection string. |
exchange_name |
str | None
|
Optional exchange name for routing. |
Initialize the asynchronous RabbitMQ event transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RabbitMQConnectionConfig
|
RabbitMQ connection configuration. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/transport.py
send(event_name, payload)
async
¶
Send a pre-serialized event payload to RabbitMQ asynchronously.
Creates a new robust connection, sends the payload to the appropriate queue, and closes the connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Routing key / queue name for the event. |
required |
payload
|
bytes
|
Pre-serialized JSON bytes. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/transport.py
options: show_root_heading: false
Event Consumer¶
spakky.plugins.rabbitmq.event.consumer
¶
RabbitMQ event consumers for integration events.
Provides synchronous and asynchronous event consumers that run as background services, consuming integration events from RabbitMQ queues and dispatching them to registered handlers.
RabbitMQEventConsumer(config)
¶
Bases: IEventConsumer, AbstractBackgroundService
Synchronous RabbitMQ event consumer.
Runs as a background service that consumes integration events from RabbitMQ queues and dispatches them to registered synchronous event handlers. Uses blocking connection for synchronous event processing.
Attributes:
| Name | Type | Description |
|---|---|---|
connection_string |
str
|
AMQP connection string. |
type_lookup |
dict[str, type[AbstractEvent]]
|
Maps consumer tags to event types. |
handlers |
dict[type[AbstractEvent], list[EventHandlerCallback[Any]]]
|
Maps event types to handler callbacks. |
connection |
BlockingConnection
|
Blocking RabbitMQ connection. |
channel |
BlockingChannel
|
Blocking channel for message consumption. |
Initialize the synchronous RabbitMQ event consumer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RabbitMQConnectionConfig
|
RabbitMQ connection configuration. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
register(event, handler)
¶
Register an event handler for a specific event type.
Multiple handlers can be registered for the same event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
type[EventT_contra]
|
The event type to handle. |
required |
handler
|
EventHandlerCallback[EventT_contra]
|
The callback function to handle the event. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
initialize()
¶
Initialize RabbitMQ connection and declare queues.
Establishes connection to RabbitMQ, creates a channel, and sets up queue consumers for all registered event handlers.
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
dispose()
¶
Clean up RabbitMQ resources.
Closes the channel and connection when the service is stopped.
run()
¶
Run the event consumer loop.
Starts consuming messages from RabbitMQ queues and blocks until the stop event is set.
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
AsyncRabbitMQEventConsumer(config)
¶
Bases: IAsyncEventConsumer, AbstractAsyncBackgroundService
Asynchronous RabbitMQ event consumer.
Runs as an async background service that consumes integration events from RabbitMQ queues and dispatches them to registered asynchronous event handlers. Uses robust connection for automatic reconnection.
Attributes:
| Name | Type | Description |
|---|---|---|
connection_string |
str
|
AMQP connection string. |
type_lookup |
dict[str, type[AbstractEvent]]
|
Maps consumer tags to event types. |
handlers |
dict[type[AbstractEvent], list[AsyncEventHandlerCallback[Any]]]
|
Maps event types to async handler callbacks. |
connection |
AbstractRobustConnection
|
Robust RabbitMQ connection for async operations. |
Initialize the asynchronous RabbitMQ event consumer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RabbitMQConnectionConfig
|
RabbitMQ connection configuration. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
register(event, handler)
¶
Register an async event handler for a specific event type.
Multiple handlers can be registered for the same event type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
type[EventT_contra]
|
The event type to handle. |
required |
handler
|
AsyncEventHandlerCallback[EventT_contra]
|
The async callback function to handle the event. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
initialize_async()
async
¶
Initialize async RabbitMQ connection and declare queues.
Establishes robust connection to RabbitMQ, creates a channel, and sets up queue consumers for all registered async event handlers.
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
dispose_async()
async
¶
Clean up async RabbitMQ resources.
Closes the channel and connection when the service is stopped.
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
run_async()
async
¶
Run the async event consumer loop.
Waits for the stop event to be set while consuming messages from RabbitMQ queues in the background.
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/event/consumer.py
options: show_root_heading: false
Configuration¶
spakky.plugins.rabbitmq.common.config
¶
Configuration for RabbitMQ connections.
Provides configuration dataclass for RabbitMQ connection parameters including host, port, credentials, and exchange settings.
RabbitMQConnectionConfig()
¶
Bases: BaseSettings
Configuration for RabbitMQ connection.
Stores connection parameters and provides a formatted connection string for establishing RabbitMQ connections.
Attributes:
| Name | Type | Description |
|---|---|---|
host |
str
|
RabbitMQ server hostname. |
port |
int
|
RabbitMQ server port. |
user |
str
|
Username for authentication. |
password |
str
|
Password for authentication. |
exchange_name |
str | None
|
Optional exchange name for pub/sub routing. |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/common/config.py
use_ssl
instance-attribute
¶
Flag indicating whether to use SSL for the connection.
host
instance-attribute
¶
RabbitMQ server hostname or IP address.
port
instance-attribute
¶
RabbitMQ server port number.
user
instance-attribute
¶
Username for RabbitMQ authentication.
password
instance-attribute
¶
Password for RabbitMQ authentication.
exchange_name = None
class-attribute
instance-attribute
¶
Optional exchange name for pub/sub message routing.
protocol
property
¶
Determine protocol based on SSL usage.
Returns:
| Type | Description |
|---|---|
str
|
'amqps' if SSL is enabled, otherwise 'amqp'. |
connection_string
property
¶
Generate AMQP connection string from configuration.
Returns:
| Type | Description |
|---|---|
str
|
Formatted AMQP connection string with credentials and host information. |
options: show_root_heading: false
Post Processor¶
spakky.plugins.rabbitmq.post_processor
¶
Post-processor for registering RabbitMQ event handlers.
Automatically discovers and registers event handlers from @EventHandler decorated classes, connecting them to RabbitMQ consumers with dependency injection.
RabbitMQPostProcessor
¶
Bases: IPostProcessor, IContainerAware, IApplicationContextAware
Post-processor that registers event handlers with RabbitMQ consumers.
Scans @EventHandler decorated classes for @event decorated methods and automatically registers them with the appropriate RabbitMQ consumer (sync or async) with proper dependency injection.
set_container(container)
¶
Set the container for dependency injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
IContainer
|
The IoC container. |
required |
set_application_context(application_context)
¶
Set the application context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context instance. |
required |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/post_processor.py
post_process(pod)
¶
Register event handlers from event handler classes.
Scans the event handler for methods decorated with @event and registers them with the appropriate RabbitMQ consumer (sync or async) based on whether the method is a coroutine function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod to process, potentially an event handler. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod, with event handlers registered if it's an event handler. |
Source code in plugins/spakky-rabbitmq/src/spakky/plugins/rabbitmq/post_processor.py
options: show_root_heading: false