Kafka源码分析(一) Intellij Idea 环境搭建
2019-09-29 本文已影响0人
81e2cd2747f1
阅读目标:在Intellij IDEA中断点调试由scala描述的Kafka源码,并且控制台可以输出日志。
将log4j配置文件放入maven工程classpath:
➜ core git:(1.0) ✗ tree -L 4
.
├── core.iml
└── src
├── main
│ ├── resources
│ │ └── log4j.properties
│ └── scala
│ └── kafka
└── test
├── resources
│ ├── log4j.properties
│ ├── minikdc-krb5.conf
│ └── minikdc.ldiff
└── scala
├── integration
├── kafka
├── other
└── unit
12 directories, 5 files
log4j.properties文件内容
# Global logging configuration 开发时候建议使用 debug
log4j.rootLogger=TRACE, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n
kafka-2.0的依赖中只有slf4j(抽象层),而没有实现层,所以需要修改build.gradle
compile(libs.zookeeper) {
// exclude module: 'slf4j-log4j12'
// exclude module: 'log4j'
exclude module: 'netty'
}
右键kafka.Kafka#main
,从main函数启动kafka。进行如下Run Configuration
配置的配置。
VM options:
-Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
Program arguments:
/Users/ericfei/Code/opensource/kafka/config/server1.properties
启动Kafka,输出如下信息,启动成功
[2019-09-29 21:39:04,574] INFO starting (kafka.server.KafkaServer)
[2019-09-29 21:39:04,577] INFO Connecting to zookeeper on localhost:2181/wacai-cluster (kafka.server.KafkaServer)
[2019-09-29 21:39:04,594] INFO Starting ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
...
[2019-09-29 21:39:06,865] INFO [KafkaServer id=1] started (kafka.server.KafkaServer)