spakky-kafka¶
Kafka 통합 — 이벤트 전송/수신
메인¶
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
이벤트 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, headers)
¶
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 |
headers
|
dict[str, str]
|
Metadata headers for trace propagation. |
required |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/transport.py
AsyncKafkaEventTransport(config)
¶
Bases: IAsyncEventTransport
Asynchronous Kafka event transport using aiokafka AIOKafkaProducer.
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, headers)
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 |
headers
|
dict[str, str]
|
Metadata headers for trace propagation. |
required |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/transport.py
options: show_root_heading: false
이벤트 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
set_propagator(propagator)
¶
Set the trace propagator for extracting trace context from messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
propagator
|
ITracePropagator
|
An ITracePropagator instance. |
required |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
register_auth_boundary(handler)
¶
Mark a registered post-processor endpoint as Kafka auth-aware.
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
set_propagator(propagator)
¶
Set the trace propagator for extracting trace context from messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
propagator
|
ITracePropagator
|
An ITracePropagator instance. |
required |
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/event/consumer.py
register_auth_boundary(handler)
¶
Mark a registered post-processor endpoint as Kafka auth-aware.
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
Auth Boundary¶
spakky.plugins.kafka.auth
¶
Authentication helpers for Kafka consumer boundaries.
KAFKA_AUTH_BOUNDARY = 'kafka'
module-attribute
¶
Provider-neutral boundary name used for Kafka AuthInvocation values.
KAFKA_AUTH_HEADERS_PARAMETER = '_spakky_kafka_headers'
module-attribute
¶
Internal endpoint keyword used to pass Kafka message headers.
KafkaHandlerAuthBinding(*, operation, protected)
dataclass
¶
KafkaAuthBoundary(container, application_context)
¶
Verify propagated snapshots and seed AuthContext for Kafka handlers.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/auth.py
seed_auth_context(headers, binding)
¶
Verify a Kafka snapshot header and store AuthContext before user code.
Source code in plugins/spakky-kafka/src/spakky/plugins/kafka/auth.py
options: show_root_heading: false
설정¶
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: StrEnum
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
후처리기¶
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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
options: show_root_heading: false