MSA

[MSA]Kafka Topic이란? zookeeper,Kafka Topic example

차노도리 2023. 5. 1. 22:22

Kafka 다운로드 

https://kafka.apache.org/downloads

 

Apache Kafka

Apache Kafka: A Distributed Streaming Platform.

kafka.apache.org

 

Zookeepr, Kafka 서버 구동

  • ./bin/zookeeper-server-start.sh ./config/zookeeper.properties
  • ./bin/kafka-server-start.sh ./config/server.properties
$KAFKA_HOME ./bin/zookeeper-server-start.sh ./config/zookeeper.properties
$KAFKA_HOME ./bin/kafka-server-start.sh ./config/server.properties

Zookeepr, Kafka 환경설정

  • zookeeper.properties
  • server.properties
$KAFKA_HOME/config/zookeeper.properties
$KAFKA_HOME/config/server.properties

 

Kafka Topic

  • Kafka Producer에서 메시지를 보내면 저장되는 장소

Kafka Topic 생성

  • ./bin/kafka-topics.sh --create --topic [토픽명] --bootstrap-server [kafka서버] --partitions [번호]
$KAFKA_HOME ./bin/kafka-topics.sh --create --topic gugbab-test-events --bootstrap-server localhost:9092 --partitions 1

Kafka Topic 목록 확인

  • ./bin/kafka-topics.sh --bootstrap-server [kafka서버] --list
$KAFKA_HOME ./bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

Kafka Topic 정보 확인

  • ./bin/kafka-topics.sh --describe --topic [토픽명] --bootstrap-server [kafka서버]
$KAFKA_HOME ./bin/kafka-topics.sh --describe --topic gugbab-test-events --bootstrap-server Localhost:9092

 

Kafka Producert 실행 (메시지 생산)

  • ./bin/kafka-console-producer.sh --broker-list [kafka서버] --topic [토픽명]
$KAFKA_HOME ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic gugbab-test-events

Kafka Consumer 실행

  • ./bin/kafka-console-consumer.sh --bootstrap-server [kafka서버] --topic [토픽명]
$KAFKA_HOME ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic gugbab-test-events --from-beginning

 

Kafka 사용 예시