生产者向 Kafka 主题发布(写入)事件,消费者订阅(读取)来自这些主题的事件。理解它们的工作原理——包括分区、偏移量和消费者组——是使用 Kafka 的基础。
生产者——写入事件
text
PRODUCERS publish events to TOPICS:
→ send a record (key, value) to a topic
→ the key determines the PARTITION (same key → same partition → ordering for that key);
no key → distributed (round-robin)
→ can configure ACKNOWLEDGMENTS (acks) for durability (wait for replicas to confirm)
→ batching, compression for throughput
消费者——读取事件
text
CONSUMERS subscribe to topics and read events:
→ read from partitions, tracking their OFFSET (position) → resume from where they left off
→ read at their OWN PACE (events are retained); can re-read (replay) from any offset
→ COMMIT offsets to record progress (so they don't reprocess on restart)
