이번 글은 카프카, 데이터 플랫폼의 최강자 라는 책을 보면서 간단히 작성 해 봤다. 간단한 실행 및 예제 프로그래밍은 책보다 공식홈페이지에 있는 문서 를 참고했다.
This post was written while reading the book Kafka, The Definitive Guide to Data Platforms. For simple execution and example programming, I referred to the official documentation rather than the book.

Apache Kafka는 실시간으로 기록 스트림을 게시, 구독, 저장 및 처리할 수 있는 분산 데이터 스트리밍 플랫폼이다. 이는 여러 소스에서 데이터 스트림을 처리하고 여러 사용자에게 전달하도록 설계가 되었다. 간단히 말해, A지점에서 B지점까지 이동하는 것뿐만 아니라 A지점에서 B지점을 비롯해 필요한 모든 곳에서 대규모 데이터를 동시에 이동할 수 있습니다.
reference: RedHat, Apache Kafka 소개
Apache Kafka is a distributed data streaming platform that can publish, subscribe, store, and process record streams in real-time. It is designed to handle data streams from multiple sources and deliver them to multiple consumers. Simply put, it can move large-scale data simultaneously not just from point A to point B, but from point A to point B and everywhere else it's needed.
reference: RedHat, Introduction to Apache Kafka
Kafka를 사용 할 때 짚고 넘어 갈 간단한 개념
Key Concepts to Understand When Using Kafka
- ZooKeeper
Apache Zookeeper는 분산 코디네이션 서비스를 제공하는 오픈 소스.
어플리케이션에서 스케쥴링 및 작업 조율을 직접 하지 않고 zookeeper가 조율을 도와준다. 안정성 확보를 위해서 클러스터로 구축이 되며 클러스터는 보통 홀수개로 구축.
Apache Zookeeper is an open source that provides distributed coordination services.
Instead of handling scheduling and task coordination directly in applications, Zookeeper helps with coordination. For reliability, it is built as a cluster, and clusters are typically configured with an odd number of nodes.
- Topic
데이터의 '주제' 라고 생각하면 쉽게 이해 할 수 있다. 데이터의 주제 / 이벤트를 Topic으로 생성하고 해당하는 Topic에 데이터를 보내고 읽을 수 있다.
예를 들어 Topic을 temperature로 설정하고, temperature Topic에 관련된 데이터를 보내고 읽을 수 있다.
Think of it as the 'subject' of data for easy understanding. You can create a Topic for data subjects/events and send and read data to/from that Topic.
For example, you can set a Topic as "temperature" and send and read data related to the temperature Topic.
- Producer
데이터를 제공하는 쪽. "떠드는 쪽" 이라고 해도 괜찮을 것 같다. 데이터를 생성하고, 이벤트를 생성하는 쪽 입니다. 설정 된 Topic에 데이터를 제공한다.
The side that provides data. You could also call it "the one that talks." It generates data and creates events. It provides data to the configured Topic.
- Consumer
데이터를 소비하는 쪽. 즉, 데이터를 필요로 하는 쪽. 데이터나 이벤트의 발생을 보고 분석하거나 저장하는 쪽으로 이어주는 역할을 할 수 도 있다.
The side that consumes data. In other words, the side that needs data. It can also serve as a bridge to analyze or store data and events as they occur.
Kafka 설치 및 실행하기
실행시키고 확인 해야 할 서비스가 많아서.. 터미널을 좀 많이 켜야겠네요 하핳…
Installing and Running Kafka
There are many services to run and check... so you'll need to open quite a few terminal windows, haha...
설치 (Download)
Installation (Download)
https://www.apache.org/dyn/closer.cgi?path=/kafka/2.8.0/kafka_2.13-2.8.0.tgz
위의 페이지에서 Kafka를 받고, 적절한 위치로 이동시켜 주자.
Download Kafka from the page above and move it to an appropriate location.
Unzip
tar -xzf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0
Kafka 실행을 위한 Zookeeper, Broker 실행하기
Running Zookeeper and Broker for Kafka Execution
// kafka_2.13-2.8.0 폴더 내의 위치에서 실행하자
// zookeeper
$ bin/zookeeper-server-start.sh config/zookeeper.properties
// broker service
$ bin/kafka-server-start.sh config/server.properties
메시지 발송을 위한 Topic 생성하기
Creating a Topic for Sending Messages
// Kafka myevent Topic 생성
$ bin/kafka-topics.sh --create --topic myevent --bootstrap-server localhost:9092
// myevent Topic 구독 현황 확인하기
$ bin/kafka-topics.sh --describe --topic myevent --bootstrap-server localhost:9092
Topic에 메시지 발송하기 (command line interface에서)
Sending Messages to a Topic (from command line interface)
$ bin/kafka-console-producer.sh --topic myevent --bootstrap-server localhost:9092
>
kafka-console-producer.sh 를 실행하면, 메시지를 계속 생성하고 보내는 역할을 한다. 때문에 콘솔창은 input이 가능한 형태로 계속 열려있다.
When you run kafka-console-producer.sh, it continuously generates and sends messages. Therefore, the console window remains open in a form that accepts input.
Topic에 발송 한 메시지 읽어오기(command line interface에서)
Reading Messages Sent to a Topic (from command line interface)
bin/kafka-console-consumer.sh --topic myevent --from-beginning --bootstrap-server localhost:9092
위의 kafka-console-producer.sh 에서 작성 한 데이터가 출력된다.
The data written in kafka-console-producer.sh above will be displayed.