工具准备:jdk1.8,scala-2.11.11,gradle-3.1,zookeeper-3.4.5,kafka-0.10.0.1-src.tgz, kafka_2.11-0.10.0.1.tgz
安装jdk
安装scala
搭建zookeeper
kafka源码构建
解压kafka-0.10.0.1-src.tgz,命令行进行kafka-0.10.0.1-src,执行gradle idea
注:
1)gradle idea,用国外的库构建的下载速度很慢,在进入项目里面,找到build.gradle文件的修改库为阿里镜像库
buildscript {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
apply from: file('gradle/buildscript.gradle'), to: buildscript
dependencies {
// For Apache Rat plugin to ignore non-Git files
classpath "org.ajoberstar:grgit:1.5.0"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
classpath 'org.scoverage:gradle-scoverage:2.0.1'
}
}
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: "jacoco"
allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}
2)执行gradle idea时,报错
* What went wrong:
A problem occurred evaluating root project 'kafka-0.10.0.1-src'.
> Failed to apply plugin [class 'org.gradle.api.plugins.scala.ScalaBasePlugin']
> No such property: useAnt for class: org.gradle.api.tasks.scala.ScalaCompileOptions
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
解决方法:打开kafka-0.10.0.1-src目录下build.gradle文件
添加如下行
[plain] view plain copy
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false
7.用intellij idea打开kafka-0.10.0.1-src
8.复制log4j.properties文件放到core模块的src/main/scala路径下,这样才能正常的显示日志
9.增加scala-sdk
10.配置启动参数
11.启动项目
12.验证
解压kafka_2.11-0.10.0.1.tgz文件,命令行进入bin/windows
1)创建topic
C:\webserver\kafka_2.11-0.10.0.1\bin\windows>kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --
partitions 1 --topic testMsg
Created topic "testMsg".
控制台日志如下:
2)执行生产者命令,产生消息:
3)执行消费者命令,消费消息:
问题:
ERROR Processor got uncaught exception. (kafka.network.Processor)
java.nio.BufferUnderflowException
解决方案:
这是客户端的jar包和集群的版本号在小版本不一致导致,保持版本号一致即可。
scala-2.11.11,kafka-0.10.0.1-src.tgz, kafka_2.11-0.10.0.1.tgz