Skip to main content

How to run Kafka from source code - Kafka Source Code

Get source code of Kafka, the version is 2.3

 git clone -b 2.3 https://github.com/apache/kafka.git

Generate Jar File

./gradlew jar

Start the zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties


Since we are mainly focus on Kafka source code, we won't spend some time to dig into how the zookeeper start by using jars directly.

Start the Kafka Server

Option 1: start with script

bin/kafka-server-start.sh config/server.properties






Option 2:

If we inspect the real command from kafka-run-class.sh which is called by kafka-start-server.sh, here is the final command to run:


exec /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/bin/java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -Djava.awt.headless=true -Xlog:gc*:file=/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../logs/kafkaServer-gc.log:time,tags:filecount=10,filesize=102400 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dkafka.logs.dir=/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../logs -Dlog4j.configuration=file:bin/../config/log4j.properties -cp /Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../core/build/dependant-libs-2.12.8/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../examples/build/libs/kafka-examples-2.3.1-SNAPSHOT-sources.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../examples/build/libs/kafka-examples-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../clients/build/libs/kafka-clients-2.3.1-SNAPSHOT-sources.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../clients/build/libs/kafka-clients-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../streams/build/libs/kafka-streams-2.3.1-SNAPSHOT-sources.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../streams/build/libs/kafka-streams-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../streams/examples/build/libs/kafka-streams-examples-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../streams/build/dependant-libs-2.12.8/rocksdbjni-5.18.3.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../tools/build/libs/kafka-tools-2.3.1-SNAPSHOT-sources.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../tools/build/libs/kafka-tools-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../tools/build/dependant-libs-2.12.8/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/api/build/libs/connect-api-2.3.1-SNAPSHOT-sources.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/api/build/libs/connect-api-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/api/build/dependant-libs/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/transforms/build/libs/connect-transforms-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/transforms/build/dependant-libs/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/runtime/build/libs/connect-runtime-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/runtime/build/dependant-libs/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/file/build/libs/connect-file-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/file/build/dependant-libs/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/json/build/libs/connect-json-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/json/build/dependant-libs/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/basic-auth-extension/build/libs/connect-basic-auth-extension-2.3.1-SNAPSHOT.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../connect/basic-auth-extension/build/dependant-libs/*:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../core/build/libs/kafka_2.12-2.3.1-SNAPSHOT-sources.jar:/Users/leizheng/vcs/github/kafka/kafka-2.3/bin/../core/build/libs/kafka_2.12-2.3.1-SNAPSHOT.jar kafka.Kafka config/server.properties

With the same setting above,  we are able to run the Kafka directly from IntelliJ IDEA



Check the Server is running or not:


bin/kafka-topics.sh --list --bootstrap-server localhost:9092


Congratulation, now we have the run Kafka from scratch. 
Get the time to enjoy the adventure of Kafka.

Compare the source code between Spring and Kafka, the Kafka's code is more modern way by using stream interfaces and other features introduced by JDK8. And it will be good start entry point for java developer to learn how to write good code.

The another source code I will suggest is Netty which provide the deep inside about how to use JAVA NIO and good practice pattern to code at parrales.


Comments

Popular posts from this blog

How to fix "ValueError when trying to compile python module with VC Express"

When I tried to compile the python, I always get compile issue as following: ------------ ... File "C:\Python26\lib\ distutils\msvc9compiler.py ", line 358, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python26\lib\ distutils\msvc9compiler.py ", line 274, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [u'path'] --------------------- Python community discussed a lot but no solution: http://bugs.python.org/issue7511 The root cause is because the latest visual studio change the *.bat file a lot especially on 64bit env. The python 2.7 didn't update the path accordingly. Based on the assumption above, the following solution worked for me. To install Visual Studio 2008 Express Edition with all required components: 1. Install Microsoft Visual Studio 2008 Express Edition. The main Visual Studio 2008 Express installer is available from (the C++ installer name is vcsetup.exe): https://ww

How to convert the ResultSet to Stream

Java 8 provided the Stream family and easy operation of it. The way of pipeline usage made the code clear and smart. However, ResultSet is still go with very legacy way to process. Per actual ResultSet usage, it is really helpful if converted as Stream. Here is the simple usage of above: StreamUtils.uncheckedConsumer is required to convert the the SQLException to runtimeException to make the Lamda clear.

Interview for System Design 1: Designing a URL Shortening service like TinyURL.

Problem:  This service will provide short aliases redirecting to long URLs. Step 1: Requirement Analysis Understand the the basic core features: 1. create short url from long url. 2. get the long url from  the short url.  Nice to have feature: 3. will url get expired in certain time? 4. could user define their customized short url? here is some questions need to clarify:  1. How long we need keep the url?  (it will have impact on storage, it is very import to understand to how long will the data be if such data will be stored in local storage). 2. Do we allow N : 1 or only 1: 1 mapping? (have impact about algorithm and data storage.  Step 2:   Estimation Of  Resource Usage common resources: data storage || web services: QPS Let's the estimation right now:  Assume DAU is about 500M,  Create: and one user will create new one item every 5 days. so the total creation per Second will be a. yearly new record: 500M/5 * 365 ~ 50G, new records a. monthly storage: 500M/5 * 100  * 30 = 100M *