[Kafka] 명령어 정리

bbbbbhyun·2025년 6월 29일

Study

목록 보기
17/28

토픽 생성

  • replication 1개, partition 1개로 example이라는 토픽을 생성
./kafka-topics --bootstrap-server http://localhost:9092 --topic example --create --partitions 1 --replication-factor 1

–create : 생성옵션
–bootstrap-server : 토픽을 생성할 카프카 클러스터를 구성하는 브로커들의 IP와 port
–replication-factor : Topic의 파티션을 복제할 복제 개수(2이면 1개의 복제본을 사용한다는 의미)
–partitions : 파티션 개수
–config는 추가적인 설정(e.g. retention.ms는 데이터 유지기간(ms) 86400000ms = 1일)

토픽 리스트 보기

./kafka-topics --bootstrap-server http://localhost:9092 --list --exclude-internal   

–list : 조회옵션
–exclude-internal : Kafka 내부 관리를 위한 Topic을 조회 대상에서 제외

토픽 상세 조회

./kafka-topics --bootstrap-server http://localhost:9092 --topic example --describe 

–describe 옵션
파티션 개수, 복제된 파티션이 위치한 브로커의 번호, 기타 토픽을 구성하는 설정 출력

토픽 옵션 수정

  • 토픽의 파티션 개수를 2개로 늘림
./kafka-topics --bootstrap-server http://localhost:9092 --topic example --alter --partitions 2 
./kafka-topics --bootstrap-server http://localhost:9092 --topic example --describe 

토픽의 파티션 수는 증가만 가능하고, 감소는 불가능

Kafka producer 연결 후 메세지 Publish

./kafka-console-producer --broker-list http://localhost:9092 --topic example

Kafka consumer 연결 후 메세지 Subscribe

./kafka-console-consumer --bootstrap-server http://localhost:9092 --topic example --from-beginning

브로커에 전송된 데이터를 폴링(polling)하여 데이터 확인
–from-beginning : 가장 처음 offset 데이터부터 폴링(polling)
‘hello world’ 라는 메세지 publish 해보기

Kafka Consumer Group & Offsets

  • Consumer group 목록
./kafka-consumer-groups --bootstrap-server http://localhost:9092 --list
  • Consumer group 의 offset 확인
./kafka-consumer-groups --bootstrap-server http://localhost:9092 --group <group_id> --describe

–decribe 옵션으로 그룹에 대한 상세 내용 조회

Consumer group 의 offset 재설정

./kafka-consumer-groups --bootstrap-server http://localhost:9092 --group <group_id> --topic example --reset-offsets --to-earliest --execute
profile
BackEnd developer

0개의 댓글