Mac
- Make sure you are navigated inside the bin directory.
- Start up the Zookeeper.
./zookeeper-server-start.sh ../config/zookeeper.properties
- Add the below properties in the server.properties
listeners=PLAINTEXT://localhost:9092
auto.create.topics.enable=false
- Start up the Kafka Broker
./kafka-server-start.sh ../config/server.properties
./kafka-topics.sh --create --topic test-topic --replication-factor 1 --partitions 4 --bootstrap-server localhost:9092
./kafka-console-producer.sh --broker-list localhost:9092 --topic test-topic
./kafka-console-producer.sh --broker-list localhost:9092 --topic test-topic --property "key.separator=-" --property "parse.key=true"
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning -property "key.separator= - " --property "print.key=true"
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --group <group-name>
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic library-events.DLT --from-beginning --property print.headers=true --property print.timestamp=true
Windows
- Make sure you are inside the bin/windows directory.
- Start up the Zookeeper.
zookeeper-server-start.bat ..\..\config\zookeeper.properties
- Start up the Kafka Broker.
kafka-server-start.bat ..\..\config\server.properties
kafka-topics.bat --create --topic test-topic --replication-factor 1 --partitions 4 --bootstrap-server localhost:9092
kafka-console-producer.bat --broker-list localhost:9092 --topic test-topic
kafka-console-producer.bat --broker-list localhost:9092 --topic test-topic --property "key.separator=-" --property "parse.key=true"
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test-topic --from-beginning
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test-topic --from-beginning -property "key.separator= - " --property "print.key=true"
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test-topic --group <group-name>
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic library-events.DLT --from-beginning --property print.headers=true --property print.timestamp=true
-
The first step is to add a new server.properties.
-
We need to modify three properties to start up a multi broker set up.
broker.id=<unique-broker-d>
listeners=PLAINTEXT://localhost:<unique-port>
log.dirs=/tmp/<unique-kafka-folder>
auto.create.topics.enable=false
- Example config will be like below.
broker.id=1
listeners=PLAINTEXT://localhost:9093
log.dirs=/tmp/kafka-logs-1
auto.create.topics.enable=false
- Provide the new server.properties thats added.
./kafka-server-start.sh ../config/server-1.properties
./kafka-server-start.sh ../config/server-2.properties
Mac
./kafka-topics.sh --bootstrap-server localhost:9092 --list
- The below command can be used to describe all the topics.
./kafka-topics.sh --bootstrap-server localhost:9092 --describe
- The below command can be used to describe a specific topic.
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topic-name>
./kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name library-events --alter --add-config min.insync.replicas=2
./kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic test-topic --partitions 40
./kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic test-topic
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group console-consumer-27773
./kafka-run-class.sh kafka.tools.DumpLogSegments --deep-iteration --files /tmp/kafka-logs/test-topic-0/00000000000000000000.log
./kafka-configs.sh --alter --bootstrap-server localhost:9092 --entity-type topics --entity-name test-topic --add-config min.insync.replicas=2
Windows
- Make sure you are inside the bin/windows directory.
kafka-topics.bat --bootstrap-server localhost:9092 --list
- The below command can be used to describe all the topics.
kafka-topics.bat --bootstrap-server localhost:9092 --describe
- The below command can be used to describe a specific topic.
kafka-topics.bat --bootstrap-server localhost:9092 --describe --topic <topic-name>
kafka-configs.bat --bootstrap-server localhost:9092 --entity-type topics --entity-name library-events --alter --add-config min.insync.replicas=2
kafka-configs.bat --bootstrap-server localhost:9092 --alter --topic test-topic --partitions 40
kafka-topics.bat --bootstrap-server localhost:9092 --delete --topic <topic-name>
kafka-consumer-groups.bat --bootstrap-server localhost:9092 --list
kafka-consumer-groups.bat --bootstrap-server localhost:9092 --describe --group console-consumer-27773
kafka-run-class.bat kafka.tools.DumpLogSegments --deep-iteration --files /tmp/kafka-logs/test-topic-0/00000000000000000000.log