Kafka proof of concept project
Everything you need to run a basic Kafka program should be within the kafka-poc repo.
All the scripts default to using the location cd C:\Programming\kafka-poc\kafka-training
as their starting point. If you have cloned this repo to somewhere else please amend the scripts before you start or else nothing will run!
- In a new terminal, start Zookeeper by running the script
\kafka-training\run-zookeeper.bat
from the command line - In a new terminal, start a Kafka server by running the script
\kafka-training\run-kafka.bat
- In a new terminal, create a Kafka topic by running the script
\kafka-training\lab1\create-topic.bat
- Running the script
\kafka-training\lab1\list-topics
will give you a list of the topics that Kafka is currently managing - In a new terminal, run the script
\kafka-training\lab1\start-producer-console
. This will start a Kafka producer in a terminal window, which will send whatever you type in the terminal to the Kafka topic you just created. You should try and send at least 4 messages to the topic. - In order to see your messages, in a new terminal, run the script
kafka-training\lab1\start-consumer-console.bat
. You should see the messages you previously sent in the new terminal, and should see any new messages you send straight away. (Note, the messages will not be in order as we have 13 partitions within this topic and our consumer is reading from all of them
- Make sure zookeeper is running, if not then run
\kafka-training\run-zookeeper.bat
in a new terminal - In a new terminal, start 1st Kafka server by running the script
\kafka-training\lab2\start-1st-server.bat
- In a new terminal, start 2nd Kafka server by running the script
\kafka-training\lab2\start-2nd-server.bat
- In a new terminal, start 3rd Kafka server by running the script
\kafka-training\lab2\start-3rd-server.bat
- Create a replicated topic (replication factor 3) by running the script
\kafka-training\lab2\create-replicated-topic.bat
. This will create a topic that is replicated over the 3 servers we just made - Running the script
\kafka-training\lab2\describe-topics.bat
will give you a list of the topics that Kafka is currently managing - In a new terminal window, run the script
start-producer-console-replicated.bat
and type out some messages you want to send. - In a new terminal, run the script
start-consumer-console-replicated.bat
. You should be able to see the messages you previously sent, and like before if you type new messages into the producer console, they should appear in the consumer console. - To demonstrate how Kafka deals with failover, if you kill one of the severs, you should still be able to send and receive messages. Running the ‘describe-topics’ script should show that Kafka is aware of a missing server and is compensating. If you bring the server back on line, ‘describe-topics’ should reflect this. You shouldn’t see a difference in how the producer and consumer work (unless you take down all the servers)
Within the Maven project, the classes “KafkaProducerExample” and “KafkaConsumerExample” are simple classes that behave similarly to the command line, and show examples of synchronous and asynchronous communication.
The UserExample project is a sends a simple user object, with a custom serializer.
The stockprices project goes much more in depth into producer and consumer config, and uses a more complicated custom serializer.
To run any of the producers/consumers within the maven project, the following scripts need to be running, each with its own terminal:
\kafka-training\run-zookeeper.bat
\kafka-training\lab2\start-1st-server.bat
\kafka-training\lab2\start-2nd-server.bat
\kafka-training\lab2\start-3rd-server.bat
\kafka-training\create-example-topic.bat