graflo.data_source.kafka¶
Kafka topic data source implementation.
Runtime consumer for Kafka connectors. Configuration is built by
:class:~graflo.architecture.contract.bindings.KafkaConnector.build_kafka_config
from contract fields plus runtime credentials from a connection provider.
Requires confluent-kafka (default package dependency).
Attributes¶
Positions = dict[tuple[str, int], int]
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
KafkaConfig
¶
Bases: ConfigBaseModel
Merged runtime configuration for Kafka consumers.
Built exclusively via :meth:KafkaConnector.build_kafka_config; not intended
for direct construction in manifests or factory helpers.
Source code in graflo/data_source/kafka.py
Attributes¶
auto_offset_reset = 'earliest'
class-attribute
instance-attribute
¶
bootstrap_servers
instance-attribute
¶
client_id = None
class-attribute
instance-attribute
¶
group_id
instance-attribute
¶
idle_ms = 2000
class-attribute
instance-attribute
¶
include_headers = False
class-attribute
instance-attribute
¶
max_wait_ms = None
class-attribute
instance-attribute
¶
poll_timeout_ms = 500
class-attribute
instance-attribute
¶
row_annotations = Field(default_factory=dict)
class-attribute
instance-attribute
¶
sasl_mechanism = None
class-attribute
instance-attribute
¶
sasl_password = None
class-attribute
instance-attribute
¶
sasl_username = None
class-attribute
instance-attribute
¶
security_protocol = 'PLAINTEXT'
class-attribute
instance-attribute
¶
topics
instance-attribute
¶
value_encoding = 'json'
class-attribute
instance-attribute
¶
Methods:¶
to_consumer_config()
¶
Build a confluent-kafka consumer config dict.
Source code in graflo/data_source/kafka.py
KafkaDataSource
¶
Bases: AbstractDataSource
Data source that consumes JSON messages from Kafka topics.
Delivery is at least once: an offset is committed only for a batch the caller acknowledged, so a batch that was read and not written is read again by the next run.
Source code in graflo/data_source/kafka.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
Attributes¶
config
instance-attribute
¶
source_type = DataSourceType.KAFKA
class-attribute
instance-attribute
¶
Methods:¶
acknowledge(batch_index)
¶
Mark a batch as written. Its offsets are committed with the next poll,
or by :meth:close, once every earlier batch is acknowledged too.
close()
¶
Commit the acknowledged batches and leave the consumer group.
Ends a read in progress: the iterator stops at its next poll.
Source code in graflo/data_source/kafka.py
iter_batches(batch_size=1000, limit=None)
¶
Poll Kafka until limit, idle timeout, or max wait is reached.
Offsets are committed only for acknowledged batches
(:meth:acknowledge); reading alone commits nothing. Call
:meth:close when done. Non-JSON-object payloads are skipped with a
warning.
Source code in graflo/data_source/kafka.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
Functions:¶
decode_kafka_json_value(raw)
¶
Decode a UTF-8 JSON object payload into a dict.
Non-object JSON (arrays, scalars) and invalid UTF-8/JSON return None.