본문 바로가기
kafka/core

여러 개의 파티션을 가지는 메시지 전송

by 개복이 2025. 4. 17.

여러 개의 파티션을 가지는 메시지 전송

파티션이 3개인 토픽 생성

kafka-topics --bootstrap-server localhost:9092 --create --topic multipart-topic --partitions 3

 

토픽 상세 확인

kafka-topics --bootstrap-server localhost:9092 --topic multipart-topic --describe

 

key 값이 없는 메시지 발행

테스트 데이터 생성

for i in {1..2000}
do
echo "test nonkey test0000000000$i" >> load.log
done

 

테스트 데이터로 메시지 발행

kafka-console-producer --bootstrap-server localhost:9092 --topic --multipart-topic < load.log

 

key 값이 없는 메시지 소비

  • 메시지를 발행한 순서와 메시지를 소비하였을 때 순서가 불일치하는 것을 확인할 수 있다.
  • 이유는 메시지를 소비할 때 파티션 단위로 배치 단위 만큼 전송하기 때문
kafka-console-consumer --bootstrap-server localhost:9092 --topic --multipart-topic --property print.partition=true --from-beginning

 

key 값이 있는 메시지 발행

kafka-console-producer --bootstrap-server localhost:9092 --topic multipart-topic --property key.separator=: --property parse.key=true

 

key 값이 있는 메시지 소비

  • key 값이 동일한 메시지의 파티션이 동일한 것을 확인할 수 있다.
kafka-console-consumer --bootstrap-server localhost:9092 --topic multipart-topic --property print.partition=true --property print.key=true --from-beginning

댓글