티스토리 뷰

반응형

카프카를 사용하다보면 토픽이나 컨슈머그룹을 확인하기위한 명령어를 사용해야 하는 경우가 많다.

처음엔 기본 command line 명령어툴을 사용했는데 사용하면서 느끼는 가장 큰 불편함은 아래 2가지였다.

  • 명령어 파라미터가 조금 장황하고
  • 클러스터를 여러대 운영한다면 "bootstrap-server" 주소를 기억해야한다

 

그래서 좀더 편하게 카프카 토픽을 다루는 명령어 툴이 없나? 하고 삽질하던끝에 꽤 좋은 녀석을 발견했다.

kafkactl 이라는 녀석이고, 다행히 내가 사용중인 macOS 에서 잘 동작한다

https://github.com/deviceinsight/kafkactl

 

 

서버주소 입력하는것에서 해방 !

kafkactl 에서는 설정파일이 존재하기 때문에 매번 서버 주소를 입력하지 않고 명령어 처리가 가능하다.

설정파일은 yaml 포맷이고, 다음과 같은 명령을 사용하면 쉽게 실행될 서버 변경이 가능해진다.

(우리가 cd 명령으로 폴더 이동하듯, 설정한 서버로 쉽게 세팅변경이 된다)

kafkactl config use-context <서버명>

 

  •  ~/.config/kafkactl/config.yml 
contexts:
  default:
    brokers:
    - localhost:9092
  # 개발서버  
  kafka-test:
    brokers:
    - 10.1.2.3:9092
  # 운영서버  
  kafka-real:
    brokers:
    - kafka.my-host.com:9092
current-context: default

 

어떤 명령어 써야했지? 헤메던것에서 해방

또 장점을 꼽자면, 기본명령은 용도에 따라 "kafka-topics" , "kafka-consumer-groups" 같은 실행파일이 달라지는데, 여기서는 kafkactl 로 통일되고 좀더 직관적이다. 파라미터를 빼먹어도 다음과 같이 명령어 구조가 나오고 파라미터도 정리가 잘 된느낌이랄까?

% kafkactl
A command-line interface the simplifies interaction with Kafka.

Usage:
  kafkactl [command]

Available Commands:
  alter       alter topics, partitions
  attach      run kafkactl pod in kubernetes and attach to it
  completion  
  config      show and edit configurations
  consume     consume messages from a topic
  create      create topics, consumerGroups, acls
  delete      delete topics, acls
  describe    describe topics, consumerGroups
  get         get info about topics, consumerGroups, acls
  help        Help about any command
  produce     produce messages to a topic
  reset       reset consumerGroupsOffset
  version     print the version of kafkactl

Flags:
  -C, --config-file string   config file. one of: [$HOME/.config/kafkactl $HOME/.kafkactl $SNAP_REAL_HOME/.config/kafkactl $SNAP_DATA/kafkactl /etc/kafkactl]
  -h, --help                 help for kafkactl
  -V, --verbose              verbose output

Use "kafkactl [command] --help" for more information about a command.

 

기본명령 vs kafkactl 실제 비교

기본툴과 kafkactl 을 사용할때 어떤 차이가 있는지 토픽과 컨슈머 그룹을 확인한다고 했을때 다음과 같은 차이가 존재한다. 딱 보면 서버정보가 생략되고, 명령어의 흐름이 더 자연스러운걸 알 수 있다.

 

  • kafkactl 에서 확인할 경우 
# 서버설정변경 : ~/.config/kafkactl/config.yml
% kafkactl config use-context kafka-test

# 1. 토픽 리스트 보기
% kafkactl get topics

# 2. 컨슈머그룹 리스트 보고
% kafkactl list consumer-groups

# 3. sample 토픽정보 확인
% kafkactl describe topic sample

# 4. app-sample 컨슈머 그룹정보 확인
% kafkactl describe consumer-group app-sample
  • 기본 툴 
# 1. 토픽 리스트 확인
% ./kafka-topics --list --bootstrap-server 10.1.2.3:9092

# 2. 컨슈머 그룹 리스트 확인 
% ./kafka-consumer-groups --list --bootstrap-server 10.1.2.3:9092

# 3. sample 토픽정보 확인
% ./kafka-topics --describe --bootstrap-server 10.1.2.3:9092 --topic sample

# 4. app-sample 그룹리스트 확인
./kafka-consumer-groups --describe --bootstrap-server 10.1.2.3:9092 --group app-sample

카프카 클러스터가 많아진다면 기본 명령어툴은 쓰기보다는 이 툴을 써보길 권해본다.

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함