一、安装JDK和Gradle环境

二、安装Scala环境

三、启动Zookeeper

  1. # windows
  2. zkServer.cmd
  3. # windows
  4. zkServer.sh start

四、从Github下载Kafka源码

  1. git clone https://github.com/apache/kafka.git

五、切换源码分支为2.8

  1. git checkout -b 2.8 origin/2.8

六、修改 build.gradle 文件

由于未知原因,直接执行 gradle idea 命令会出错,所以需要修改 build.gradle 文件。

6.1 注释 consistentResolution

  1. java {
  2. // consistentResolution {
  3. // resolve the compileClasspath and then "inject" the result of resolution as strict constraints into the runtimeClasspath
  4. // useCompileClasspathVersions()
  5. // }
  6. }

6.2 修改 Maven 仓库

  1. repositories {
  2. maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
  3. mavenCentral()
  4. }

6.3 添加 SLF4j JAR包

搜索 project(':core'),在 dependencies 中添加以下代码:

  1. compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
  2. compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30'

七、添加log4j.properties配置文件

config/server.properties 配置文件复制到 /core/src/main/resources 目录下。
image.png

八、使用 IDEA 打开 Kafka 源码项目

安静等待 IDEA 导入 Kafka 源码,不需要做其它工作。

九、启动 Kafka Broker

在启动之前,我们需要经过以下配置:
image.png
即添加 server.properties 文件相对路径。
同时,我们还根据需要修改 Server.properties 配置项,比如 log.dirszookeeper.connect 等。
经过以上操作,就可以顺利启动 Kafka Broker 端服务了。入口 main 方法在 core/src/main/scala/kafka/kafka#main
image.png

成功启动后的日志输出如下图所示:
kafka broker 端成功启动日志输出.png