카프카/Kakfa Topic, Producer, Consumer

Producer와 Consumer

webmaster 2025. 7. 17. 23:03
728x90

Producer와 Consumer

Producer와 Consumer

  • producer는 Topic에 메시지를 보냄(메시지 write)
    • Producer는 성능/로드밸런싱/가용성/업무 정합성을 고려하여 어떤 브로커의 파티션으로 메시지를 보내야 할지 전략적으로 결정됨
  • Consumer는 Topic에서 메시지를 읽어 들임
    • 여러 개의 Consumer들로 구성될 경우 어떤 브로커의 파티션에서 메시지를 읽어 들일지 전략적으로 결정함

Producer 상세

producer 상세

Consumer 상세

Consumer 상세

  • Kafka Cunsumer는 poll() 메서드를 이용하여 주기적으로 브로커의 토픽 파티션에서 메시지를 가져옴
  • 메시지를 성공적으로 가지고 왔으면 Commit()을 통해서, __consumer_offset에 다음에 읽을 offset 위치를 기재한다.

Consumer의 auto.offset.reset

Partition

  • consumer가 topic에 처음 접속하여 메시지를 가져올 때 가장 오래된 처음 offset부터 가져올 것인지, 가장 최근인 마지막 offset부터 가져올 것인지를 설정하는 파라미터
  • auto.offset.reset = earlist: 처음 offset부터 읽음(0)
  • auto.offset.reset = latest: 마지막 offset부터 읽음(8)
  • kafka-console-consumer 명령어를 사용할 때, --from-beginning을 사용해야만 auto.offset.reset이 earlist로 지정된다.

실습

1) test Topic 생성

2) Producer 생성

3) Consumer 생성

auto.offset.reset = latest라, 노출이 안됨(기본값)
auto.offset.reset = earlist라, 노출(--from-beginning)

 

728x90