Code is read twice as often as it is written — and the Kafka consumer loop is the code nobody enjoys re-reading. WKafka turns the entire consumer skeleton into a single, clean decorator.
This is Day 01 of the WKafka Open-Source Engineering Series.
The Pain Points We Faced
- Hand-rolling
while Trueconsumer loops in every single microservice. - Scattered JSON deserialization
try/exceptblocks swallowing exceptions silently. - Ugly shutdown handling leaving dangling consumer group partition assignments.
The Implementation
from wkafka import WKafka
kafka = WKafka(dynamic_group_id=True)
@kafka.consumer(topic="orders", format="json")
def on_order(msg):
print(f"New order processed: {msg.value}")
Why This Architecture Wins
-
Zero Boilerplate: Single
@kafka.consumerdecorator defines the entire loop. -
Safe Deserialization:
format='json'automatically parses payloads cleanly. -
Auto Config: Resolves
KAFKA_SERVERenvironment variable withlocalhost:9092fallback.
Verification & Status
Tested and verified with Apache Kafka against real broker clusters. Fully compatible with Python 3.9 through 3.14 with strict typing.
Author: William Steve Rodríguez Villamizar (Wisrovi)
Top comments (0)