
# bin/kafka-topics.sh --bootstrap-server <kakfa 주소> --create --topic <토픽명>
$ bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--create \
--topic email.send
# bin/kafka-topics.sh --bootstrap-server <kakfa 주소> --list
$ bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--list
# bin/kafka-topics.sh --bootstrap-server <kakfa 주소> --describe --topic <토픽명>
$ bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--describe --topic email.send
# bin/kafka-topics.sh --bootstrap-server <kafka 주소> --delete --topic <토픽명>
$ bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--delete --topic email.send
$ bin/kafka-topics.sh \
--bootstrap-server localhost:9092 \
--list
# email.send라는 토픽에 메시지 넣기
$ bin/kafka-console-producer.sh \
--bootstrap-server localhost:9092 \
--topic email.send
# 위 명령어 입력 후 넣을 메시지 내용 입력하고 Enter 누르기
hello1
hello2
hello3
# 입력 다 했으면 Ctlr + c로 입력 상태 종료하기
# email.send라는 토픽에 있는 메시지 꺼내기
$ bin/kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic email.send \
--from-beginning
--property print.partition=true 메시지의 파티션 번호 출력 Partition:0
--property print.offset=true 메시지의 오프셋 번호 출력 Offset:5
--property print.key=true Key도 같이 출력 Key:user001
--property key.separator=" : " Key와 Value 사이 구분자 설정 Key:user001 : { ... }
[용어 정리]
- 컨슈머: 카프카의 메시지를 처리하는 주체
- 컨슈머 그룹: 1개 이상의 컨슈머를 하나의 그룹으로 묶은 단위
- 오프셋: 메시지의 순서를 나타내는 고유 번호 (0부터 시작)
$ bin/kafka-console-consumer.sh \
--bootstrap-server localhost:9092 \
--topic email.send \
--from-beginning \
--group email-send-group
$ bin/kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--list
$ bin/kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--group email-send-group \
--describe
$ bin/kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--delete \
--group email-send-group
$ bin/kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--list