Spring Cloud로 개발하는 MSA/데이터 동기화를 위한 Apache Kafka의 활용

Apache Kafka 사용 - Producer/Consumer

webmaster 2022. 2. 7. 10:48
728x90

Kafka 서버 기동

  • 기동시 properties로 매개변수로 주면 된다.
    • KafkaServer를 기동 하기 위해 zookeeper를 먼저 기동 해야 한다.
    • Zookeeper 기동 하기
      • ./bin/windows/zookeeper-server-start.bat ./config/zookeeper.properties
    • KafkaaServer 기동 하기
      • ./bin/windows/kafka-server-start.bat ./config/server.properties
  • Kafka는 데이터를 전송하게 되면 Topic에 저장이 된다
    • 사용자가 임의로 Topic을 생성해 줄 수도 있다.
    • Topic에 관심이 있다고 등록한 Consumer가 있다면 Topic에 데이터 업데이트된다면 Consumer들에게 전달된다
  • Topic 생성하기
    • ./bin/windows/kafka-topics.bat --bootstrap-server localhost:9092 --create --topic quickstart-events --partitions 1
  • Topic 목록 보기
    • ./bin/windows/kafka-topics.bat --bootstrap-server localhost:9092 --list
  • Topic 정보 보기
    • ./bin/windows/kafka-topics.bat --bootstrap-server localhost:9092 --describe --topic quickstart-events
  • 메시지 생성(메시지 보내는 쪽 기동)
    • producer 실행
    • ./bin/windows/kafka-console-producer.bat --broker-list localhost:9092 --topic quickstart-events
  • 메시지 소비(메시지 받는 쪽 기동)
    • consumer 실행 
    • ./bin/windows/kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic quickstart-events --from-beginning

최종 테스트

 

Kafka client

 

Clients - Apache Kafka - Apache Software Foundation

How The Kafka Project Handles Clients Starting with the 0.8 release we are maintaining all but the jvm client external to the main code base. The reason for this is that it allows a small group of implementers who know the language of that client to quickl

cwiki.apache.org

728x90