DB/Kafka

[Kafka] Kafka Topic 삭제

jungmin.park 2023. 12. 13. 19:11

Docker 에 Kafka가 설치되어있다고 가정한다.

(base) bagjeongmin@bagjeongmin-ui-MacBookAir ~ % docker ps -a
CONTAINER ID   IMAGE                    COMMAND                  CREATED        STATUS       PORTS                                                NAMES
6ddf989d6e5b   wurstmeister/kafka       "start-kafka.sh"         42 hours ago   Up 2 hours   0.0.0.0:9092->9092/tcp                               kafka
f6443c680f8c   wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   42 hours ago   Up 2 hours   22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp   zookeeper
c3886478e433   redis                    "docker-entrypoint.s…"   45 hours ago   Up 9 hours   0.0.0.0:6379->6379/tcp                               myredis
c36c8a7f88e2   mysql                    "docker-entrypoint.s…"   2 days ago     Up 9 hours   33060/tcp, 0.0.0.0:3307->3306/tcp                    mysql

 

도커 kafka에 접속

docker exec -it 6ddf989d6e5b /bin/bash

 

kafka /opt/kafka/config/server_properties 설정

delete.topic.enable = true

 

kafka 재시작

 

 

kafka /opt/kafka/bin으로 이동

root@6ddf989d6e5b:/# cd /opt/kafka/bin/
root@6ddf989d6e5b:/opt/kafka/bin# ls
connect-distributed.sh	      kafka-consumer-perf-test.sh	   kafka-producer-perf-test.sh	       kafka-verifiable-producer.sh
connect-mirror-maker.sh       kafka-delegation-tokens.sh	   kafka-reassign-partitions.sh        trogdor.sh
connect-standalone.sh	      kafka-delete-records.sh		   kafka-replica-verification.sh       windows

 

 

kafka topic 리스트 조회

root@6ddf989d6e5b:/opt/kafka/bin# kafka-topics.sh --list --bootstrap-server localhost:9092
Topic
__consumer_offsets
coupon_event
testTopic
ticket_stock

 

kafka topic 삭제

root@6ddf989d6e5b:/opt/kafka/bin# kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic coupon_event
  • kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic coupon_event