kafka

[Kafka] Kafka 설치 및 producer / consumer 테스트

nan2 2023. 10. 17. 12:19
반응형

kafka 설치

해당 사이트에 들어가서 Binary downloads -> Scala 언어로 선택하여 설치

(Scala 2.13  - kafka_2.13-3.6.0.tgz (asc, sha512) 설치함)

 

Apache Kafka

Apache Kafka: A Distributed Streaming Platform.

kafka.apache.org

 

 

Kafka 폴더

다운로드 파일의 알집을 풀면 /bin 과 /config 폴더가 존재한다.

/bin 폴더: kafka, zookeeper를 start, stop 할 수 있는 스크립트 존재함

* windows os 사용자의 경우 /bin/winsows에 .bat 존재함

/config 폴더: kafka, zookeeper 관련 설정 파일 존재함

 

 

Kafka 구동

zookeeper 먼저 구동 후 kafka 구동하는 순서

* zookeeper란  브로커(kafka 애플리케이션서버)의 상태, 장애 등에 대한 체크, 복구 관리를 위한 코디네이터

 

터미널에서 kafka_2.13-3.6.0 폴더로 이동

 

zookeeper 구동

./bin/zookeeper-server-start.sh ./config/zookeeper.properties

 

kafka 서버 구동

./bin/kafka-server-start.sh ./config/server.properties

 

 

* 기본 포트 번호가 9092 인데 이미 사용중이라고 뜬다면 해당 포트번호의 프로세스를 종료하거나

/config/server.properties 파일에서 사용할 포트번호를 변경해주면 된다!

 

아래와 같이 주석을 해제하고 원하는 포트번호 입력하면 끝


############################# Socket Server Settings #############################

# The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9093

 

topic 생성

./bin/kafka-topics.sh --bootstrap-server localhost:9093 
--create --topic quickstart-events --partitions 1

 

topic 목록 조회

./bin/kafka-topics.sh --bootstrap-server localhost:9093 --list

 

topic 상세 조회

./bin/kafka-topics.sh --bootstrap-server localhost:9093 --describe --topic quickstart-events

 

kafka console producer 실행

./bin/kafka-console-producer.sh --broker-list localhost:9093 --topic quickstart-events

 

kafka console consumer 실행

./bin/kafka-console-consumer.sh --bootstrap-server localhost:9093 
--topic quickstart-events --from-beginning

--bootstrap-server : 어디서 데이터를 가져올껀지 서버 주소

--topic : 해당하는 topic에 변동사항이 생기면 값을 가져오도록 topic 지정

--from-beginning : 모든 메시지를 처음부터 가지고 온다.

 

 

Kafka Test

Producer

Producer

consumer

consumer

반응형