Kafka
Kafka 토픽 삭제하기
예발이
2022. 2. 1. 16:48
카프카의 토픽을 삭제하는 것은 주키퍼에 있는 해당 토픽의 파일, 디렉토리를 삭제하는 것을 말한다.
일반적으로 알려진 토픽 삭제 방법인 kafka-topics.sh을 이용해서 토픽을 삭제하면 'already marked for deletion'이라는 메시지만 나타나고 정상적으로 삭제가 안 된다.
이 경우 다시 토픽을 생성할 수도 없으며 해당 토픽으로 들어온 메시지도 처리가 안 된다.
사전작업
카프카 설정 파일인 'config/server.properties'에 'delete.topic.enable=true' 설정을 추가한다.
해당 설정을 추가하고 카프카를 재시작 해준다.
bin/kafka-server-stop.sh # 카프카 중단
bin/kafka-server-start.sh -daemon config/server.properties # 카프카 재시작
Zookeeper shell에 접근하기
카프카 토픽을 완전히 삭제하기 위해서는 주키퍼 쉘에서 해당 토픽의 디렉토리, 파일을 삭제해주어야 한다.
bin/zookeeper-shell.sh localhost:2181
제거할 토픽 조회
ls /brokers/topics
토픽 삭제
'hello.kafka'와 'hello.kafka2' 토픽을 삭제할 것이다.
rmr /brokers/topics/hello.kafka
해당 명령어는 deprecated 되어 'deleteall'명령어를 사용해도 좋다.
deleteall /brokers/topics/hello.kafka2
토픽 삭제 확인
/bin/kafka-topics.sh --list --zookeeper <host>:<port>
'hello.kafka'와 'hello.kafka2' 토픽이 삭제된 것을 볼 수 있다.