Kafka with quickstart

Tags:

[kafka페이지] https://kafka.apache.org/quickstart

1. 코드 다운로드

[다운로드] https://www.apache.org/dyn/closer.cgi?path=/kafka/2.3.0/kafka_2.12-2.3.0.tgz

tar -xzf kafka_2.12-2.3.0.tgz

cd kafka_2.12-2.3.0

2. 서버 시작

실행은 zookeeper를 먼저한다. 그 이유는 zookeeper가 카프카의 노드를 관리하기 때문이다.

2-1. zookeeper 서버 시작

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

여기에서 카프카가 연결이 되어있지 않으면 Reading 상태로 있는다.

[2019-09-25 22:49:37,189] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)

2-2. kafka 서버 시작

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

3. topic 만들기(test 토픽)

bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

replica는 몇개를 복제할 것인 지, partition은 topic을 몇개로 나눌지를 의미한다.

4. topic 확인하기

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

test 라고 나오면 성공

5. 메세지 보내기

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

6. comsumer 시작하기

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

7. multi-broker cluster 설정하기