create-list-delete-topics
✅ CLI를 활용한 Kafka 조작
이전 강의의 그림에서는 백엔드 서버(Spring Boot)로만 Kafka를 조작할 수 있는 것처럼 표현했지만, 실제로는 CLI로도 Kafka의 모든 기능을 조작할 수 있다.
그럼 자주 사용하는 기능 중 하나인 ‘토픽(Topic)’에 관련된 명령어를 지금부터 배워보자.
✅ 토픽 생성하기
# kafka 디렉터리 안에서 아래 명령어를 실행시켜야 함
$ cd kafka_2.13-4.0.0
# 토픽 생성
# 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