Instructions along with sample code base for basic kafka project
#Source: https://www.udemy.com/apache-kafka/
- Install brew if needed: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Download and Setup Java 8 JDK:
- brew tap caskroom/versions
- brew cask install java8
- Download & Extract the Kafka binaries from https://kafka.apache.org/downloads
- Install Kafka commands using brew: brew install kafka
- Create data/zookeeper, data/kafka in folder
- Edit Zookeeper & Kafka configs using a text editor
- zookeeper.properties: dataDir=/your/path/to/data/zookeeper
- server.properties: log.dirs=/your/path/to/data/kafka
- Start Zookeeper (run in installed kafka directory): zookeeper-server-start config/zookeeper.properties
- Start Kafka (run in installed kafka directory): kafka-server-start config/server.properties
- Kafka Topics
- Create Kafka Topic: kafka-topics --zookeeper 127.0.0.1:2181 --topic topic1 --create --partitions 3 --replication-factor 1
- List Kafka Topics: kafka-topics --zookeeper 127.0.0.1:2181 --list
- Describe Topic: kafka-topics --zookeeper 127.0.0.1:2181 --topic topicName --describe
- Delete Topic: kafka-topics --zookeeper 127.0.0.1:2181 --topic topicName --delete
- Kafka Producer Consumer
- produce message for a particular topic: kafka-console-producer --broker-list 127.0.0.1:9092 --topic topic1
- Consume message from topic from beginning: kafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic topic1 --from-beginning
- Consume with consumer group: kafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic topic1 --group consumer-group-1
- List all consumer groups: kafka-consumer-groups --bootstrap-server localhost:9092 --list