spakky-kafka¶
Kafka 통합 — 이벤트 전송/수신
Main¶
spakky.plugins.kafka.main
¶
initialize(app)
¶
Initialize the spakky-kafka plugin.
Registers Kafka consumers, transports, and post-processor.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/main.py
options: show_root_heading: false
Event Transport¶
spakky.plugins.kafka.event.transport
¶
KafkaEventTransport(config)
¶
Bases: IEventTransport
Synchronous Kafka event transport using confluent_kafka Producer.
Initialize the Kafka producer with connection config.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/transport.py
send(event_name, payload)
¶
Send a pre-serialized event payload to Kafka.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Topic name (typically the event class name). |
required |
payload
|
bytes
|
Pre-serialized JSON bytes. |
required |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/transport.py
AsyncKafkaEventTransport(config)
¶
Bases: IAsyncEventTransport
Asynchronous Kafka event transport using confluent_kafka AIOProducer.
Initialize the async Kafka transport with connection config.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/transport.py
send(event_name, payload)
async
¶
Asynchronously send a pre-serialized event payload to Kafka.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Topic name (typically the event class name). |
required |
payload
|
bytes
|
Pre-serialized JSON bytes. |
required |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/transport.py
options: show_root_heading: false
Event Consumer¶
spakky.plugins.kafka.event.consumer
¶
KafkaEventConsumer(config)
¶
Bases: IEventConsumer, AbstractBackgroundService
Synchronous Kafka event consumer that polls messages and dispatches to handlers.
Initialize the Kafka consumer with connection config.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
register(event, handler)
¶
Register a handler for the given event type.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
initialize()
¶
Create Kafka topics and subscribe the consumer.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
run()
¶
Poll Kafka for messages and route them to registered handlers.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
AsyncKafkaEventConsumer(config)
¶
Bases: IAsyncEventConsumer, AbstractAsyncBackgroundService
Asynchronous Kafka event consumer that polls messages and dispatches to handlers.
Initialize the async Kafka consumer with connection config.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
register(event, handler)
¶
Register an async handler for the given event type.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
initialize_async()
async
¶
Create Kafka topics and subscribe the async consumer.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
run_async()
async
¶
Poll Kafka asynchronously for messages and route them to handlers.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
options: show_root_heading: false
Configuration¶
spakky.plugins.kafka.common.config
¶
Configuration for Kafka connections.
Provides configuration dataclass for Kafka connection parameters including bootstrap servers, consumer group, and security settings.
AutoOffsetResetType
¶
Bases: str, Enum
Kafka consumer auto offset reset policies.
KafkaConnectionConfig()
¶
Bases: BaseSettings
Kafka connection configuration loaded from environment variables.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/common/config.py
group_id
instance-attribute
¶
Kafka consumer group identifier.
client_id
instance-attribute
¶
Kafka client identifier.
bootstrap_servers
instance-attribute
¶
Kafka bootstrap servers.
security_protocol = None
class-attribute
instance-attribute
¶
Security protocol for Kafka connection.
sasl_mechanism = None
class-attribute
instance-attribute
¶
SASL mechanism for Kafka authentication.
sasl_username = None
class-attribute
instance-attribute
¶
SASL username for Kafka authentication.
sasl_password = None
class-attribute
instance-attribute
¶
SASL password for Kafka authentication.
number_of_partitions = 1
class-attribute
instance-attribute
¶
Default number of partitions for created topics.
replication_factor = 1
class-attribute
instance-attribute
¶
Default replication factor for created topics.
auto_offset_reset = AutoOffsetResetType.EARLIEST
class-attribute
instance-attribute
¶
Consumer auto offset reset policy (earliest, latest, none).
poll_timeout = 1.0
class-attribute
instance-attribute
¶
Consumer poll timeout in seconds.
options: show_root_heading: false
Post Processor¶
spakky.plugins.kafka.post_processor
¶
KafkaPostProcessor
¶
Bases: IPostProcessor, IContainerAware, IApplicationContextAware
Post-processor that registers event handlers with Kafka consumers.
Scans @EventHandler decorated classes for @event decorated methods and automatically registers them with the appropriate Kafka 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-kafka/src/spakky/plugins/kafka/post_processor.py
post_process(pod)
¶
Register event handlers from event handler classes.
Scans the event handler for methods decorated with @on_event and registers them with the appropriate Kafka consumer (sync or async) based on whether the method is a coroutine function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod, with event handlers registered if it's an event handler. |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/post_processor.py
options: show_root_heading: false