DevOps/Kafka

Kafka - 간단한 이론 및 명령어

beomzh 2023. 7. 7. 13:11
728x90
반응형

kafka=> Producer -> kafka Server -> Consumer

  • 비동기 처리를 위한 메시징 (FIFO)

kafka-topics.sh

  • 토픽에 관련된 작업을 있는 스크립트

 

sh bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --topic test-topic

  • test topic명의 topic 생성

 

sh bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --partitions 10--replication-factor 1--topic test-topic2 --config retention.ms=172800000

  • 원하는 설정을 입력한 topic 생성

 

sh bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic test-topic --describe

  • topic 설정 정보 확인

 

sh bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic test-topic --alter --partitions 3

  • topic 설정 변경( 파티션은 줄일수는 없다.)

 

kafka-configs.sh

  • 일부 옵션들을 설정하는 스크립트

 

sh bin/kafka-configs.sh --bootstrap-server localhost:9092 --broker 0--all --describe

  • 카프카 브로커 설정 확인

 

kafka-console-producer.sh

  • 카프카 브로커에 메시지를 전송 하는 스크립트

 

sh bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test-topic

  • 메시지 설정 X

sh bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test-topic --property "parse.key=true"--property "key.separator=:"

  • 메시지 설정 O

 

kafka-console-consumer.sh

  • 카프카에 적재된 데이터를 가져오는 스크립트

sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \

--topic test-topic \

--property print.key=true \ ->console 출력여부

--property key.seperator=: \ ->key,value 파싱 구분

--from-beginning\

--max-messages 3\

--partition 0

 

 

  • --from-beginning 옵션은 토픽에 저장된 가장 처음 데이터 부터 출력
  • print.key=true 옵션은 토픽에 저장된 데이터 , 가져오기
  • --max-messages 옵션은 데이터 개수를 지정
  • --partition 옵션은 특정 파티션에서 데이터 가져오기

 

kafka-consumer-group.sh

  • 컨슈머 그룹을 다루기 위한 스크립트

 

sh bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

  • 전체 리스트 보기

sh bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test-group --describe

  • 상세 보기

 

  • CURRENT-OFFSET : 현재까지 가져간 레코드의 오프셋 위치
  • LOG-END-OFFSET : 마지막 레코드의 오프셋 위치
  • LAG : LOG-END-OFFSET - CURRENT-OFFSET = 지연된 레코드 수

 

오프셋 리셋하기

  • --reset offsets 옵션을 이용해 리셋 가능
728x90
반응형