API¶
pico_kafka.decorators ¶
Marker decorators for the two sides of Kafka messaging.
Consumer side: @kafka_consumer on a component method subscribes it to a topic; the method receives the JSON-decoded record value.
Producer side: @kafka_producer on a class of @produce stubs turns it into an injectable component whose methods send their message argument as a JSON value (same generated-implementation idiom as pico-httpx clients and pico-rabbitmq publishers).
kafka_consumer(topic, *, group_id='') ¶
Subscribe a component method to topic.
group_id defaults to the kafka.group_id setting; give each independent projection its own group to fan the stream out.
Source code in src/pico_kafka/decorators.py
kafka_producer(cls) ¶
Turn a class of @produce stubs into an injectable component.
Source code in src/pico_kafka/decorators.py
produce(topic) ¶
Generate a producing implementation for a stub method.
The stub's message argument (any JSON-serializable value) is the record value. Sync stubs block until the broker acks; async stubs await it.
Source code in src/pico_kafka/decorators.py
pico_kafka.registrar ¶
Connection owner and dispatcher.
Runs a dedicated asyncio loop in a daemon thread (same architecture as pico-rabbitmq): consumers and producers work in any app without lifespan wiring. Each @kafka_consumer method gets its own AIOKafkaConsumer task; records resolve their component through the container per message.
Failure policy: a consumer method that raises is logged and its record is skipped — offsets keep advancing so a poison record cannot stall the partition. Reprocess from your monitoring, not from a hot loop.