Kafka 토픽

Apache Kafka 입문

Mike Metzger

Data Engineering Consultant

토픽이란?

  • 토픽은 이벤트의 논리적 그룹입니다
    • 관계형 데이터베이스의 테이블과 유사합니다
    • 이벤트 로그
    • 메시지는 불변입니다
    • 토픽의 메시지는 읽기/쓰기만 가능하며 수정할 수 없습니다
    • 메시지는 보존 기간에 따라 삭제될 수 있습니다

Kafka 토픽 일러스트.png

Apache Kafka 입문

토픽 생성

  • 토픽 생성 방법은 여러 가지가 있습니다
  • 여기서는 bin/kafka-topics.sh 스크립트를 사용합니다
    bin/kafka-topics.sh 
        --bootstrap-server <server> 
        --topic <topicname>
        --create
    
  • 예시
    $ bin/kafka-topics.sh --bootstrap-server localhost:9092 \
    --topic orders --create
    
Created topic orders
Apache Kafka 입문

기타 옵션

  • bin/kafka-topics.sh --create의 선택적 인수

    • --replication-factor <x>
      • 토픽의 복제 계수를 지정합니다
    • --partitions <x>
      • 파티션 수를 수동으로 지정합니다
  • 예시

    $ bin\kafka-topics.sh --bootstrap-server localhost:9092 \
    --topic orders --create --replication-factor 3 \
    --partitions 3
    
Created topic orders
Apache Kafka 입문

--describe

  • bin/kafka-topics.sh --bootstrap-server <server> --topic <topicname> --describe

    • 토픽 설정 세부 정보를 확인합니다
  • 예시

    $ bin/kafka-topics.sh --bootstrap-server localhost:9092 \
       --topic orders --describe
    
Topic: orders-new TopicId: <topicid> PartitionCount: 3 ReplicationFactor: 1    
  Configs:
    Topic: orders-new    Partition: 0    Leader: 0    Replicas: 0    Isr: 0
    Topic: orders-new    Partition: 1    Leader: 0    Replicas: 0    Isr: 0
    Topic: orders-new    Partition: 2    Leader: 0    Replicas: 0    Isr: 0
Apache Kafka 입문

토픽 삭제

  • bin/kafka-topics.sh --bootstrap-server <server> --topic <topicname> --delete
    • Kafka 서버에서 토픽을 삭제합니다
    • 토픽을 삭제하면 해당 토픽의 모든 메시지도 삭제됩니다
  • 예시
    $ bin/kafka-topics.sh --bootstrap-server localhost:9092
      --topic orders --delete
    
$
Apache Kafka 입문

연습해 봅시다!

Apache Kafka 입문

Preparing Video For Download...