728x90

작업 환경

OS: Ubuntu

Tool: Intellij

Builder: gradle

Framework: Spring-Boot

Language: Java

KafkaVersion: kafka_2.13

Kafka 설치 및 실행

  1. zookeeper 실행
# 다운받은 kafka 디렉토리 내에서 실행하였을 때 경로
xxx@kafka:~/kafka_2.13-3.6.1$ ./bin/zookeeper-server-start.sh ./config/zookeeper.properties 
  1. kafka-server 실행
xxx@kafka:~/kafka_2.13-3.6.1$ ./bin/kafka-server-start.sh ./config/server.properties
  1. topic 생성 - 이벤트 저장할 주제
xxx@kafka:~/kafka_2.13-3.6.1$ ./bin/kafka-topics.sh --create --topic ${원하는topic명:kafka-test} --bootstrap-server ${사용하길 원하는 주소:localhost:9092}
  1. topic 생성 확인
xxx@kafka:~/kafka_2.13-3.6.1$ ./bin/kafka-topics.sh --describe --topic ${topicName:kafka-test}  --bootstrap-server ${Address:localhost:9092}
Topic: kafka-test    TopicId: JW42CEjhS1qqnwIZ1cvdzQ    PartitionCount: 1    ReplicationFactor: 1    Configs: 
    Topic: kafka-test    Partition: 0    Leader: 0    Replicas: 0    Isr: 0
  1. Producer로 Event 발신
xxx@kafka:~/kafka_2.13-3.6.1$ ./bin/kafka-console-producer.sh --topic ${topicName:kafka-test} --bootstrap-server ${Address:localhost:9092}
>This is my first event
  1. Consumer로 Event수신
xxx@kafka:~/kafka_2.13-3.6.1$ ./bin/kafka-console-consumer.sh --topic ${topicName:kafka-test} --bootstrap-server ${Address:localhost:9092}

Docker로 작업

  1. Apache Kafka Image Download
docker pull apache/kafka:3.7.0
  1. Kafka Docker Container 생성 및 실행
docker run -p 9092:9092 apache/kafka:3.7.0 

 


참고

https://kafka.apache.org/quickstart

 

작업공간

https://github.com/KrongDev/kafka

728x90

+ Recent posts