Producer gửi message đến một topic và Kafka tự động phân phối message vào các partition (theo key hash, round-robin, hoặc custom partitioner).
- Cấu hình quan trọng của producer:
acks(0=fire-and-forget, 1=leader ack, all=tất cả ISR ack),retries,batch.sizevàlinger.msđể tối ưu throughput. - Consumer đọc message từ partition theo offset và có thể commit offset tự động (
enable.auto.commit=true) hoặc thủ công. - Cấu hình quan trọng của consumer:
auto.offset.reset(earliest/latest),max.poll.records,session.timeout.ms. - Trong thực tế, nên dùng manual commit để tránh mất message khi consumer crash trước khi xử lý xong.