// Apache Kafka down$ wget <https://dlcdn.apache.org/kafka/3.1.0/kafka_2.13-3.1.0.tgz>// 압축 해제$ tar zxvf kafka_2.13-3.1.0.tgzkafka_2.13-3.1.0/// zookeeper 실행$ bin/zookeeper-server-start.sh config/zookeeper.properties// zookeepr 실행 확인.$ ./ bin/zookeeper-shell.sh localhost:2181// broker를 띄우기 위한 설정$ vi config/server.properties31 line '#' 제거및listeners =127.0.0.1:9092 기입 후 저장.// broker 실행$ bin/kafka-server-start.sh config/server.properties
위의 사진은 주키퍼 실행, 아래의 사진은 브로커 실행
Topic 생성
// bin 폴더로 이동$ cd bin// topic 생성$ kafka-topics.sh--create --topic fastcampus --bootstrap-server localhost:9092// topic 생성 확인$ kafka-topics.sh--list --topic fastcampus --bootstrap-server localhost:9092
topic name 생성 제약
공백 불가
‘_’ , ’.’ 은 내부의 메트릭과의 충돌로 인해 권장하지 않는다.
name max length = 249
Message Producing
// 메시지를 입력하기 위해 producer-console로 이동$ ./kafka-console-producer.sh--bootstrap-server localhost:9092--topic fastcampus// producinghellofastcampus
Message Consuming
// consume을 시작한 뒤 produce된 메시지가 보인다.$ ./kafka-console-consumer.sh--bootstrap-server localhost:9092--topic fastcampus// 전체 message를 보고 싶은 경우 --from-beginning 옵션을 추가.$ ./kafka-console-consumer.sh--bootstrap-server localhost:9092--topic fastcampus --from-beginning