windows下IntelliJ IDEA搭建kafka源碼環境

來源:互聯網
上載者:User

標籤:成功   led   between   啟動參數   windows磁碟   其他   控制台   getting   count   

於kafka核心原理的資料,網上有很多,但是如果不自己研究其源碼,永遠是知其然而不知所以然。下面就來示範如何在windows環境下來編譯kafka源碼,並通過IntelliJ IDEA開發工具搭建kafka的源碼環境,以方便在本地通過debug調試來研究kafka的內部實現機制。

具體步驟:

(1)安裝jdk,版本為1.8.0_131,配置JAVA_HOME:

 

(2)安裝scala,版本為 2.10.6,配置SCALA_HOME:

 

(3)安裝Gradle,版本為 3.1,配置GRADLE_HOME:

 

(4)安裝Maven,版本為 3.2.1,配置MAVEN_HOME:

 

(5)安裝zookeeper,版本為3.4.6

到zookeeper官網下載壓縮包,解壓到windows的任意磁碟目錄下,將conf目錄下的zoo_sample.cfg複製一份,將其名稱修改為zoo.cfg,然後開啟,指定dataDir=D:\\java\\zookeeper-data\\3.4.6-data,比如我的配置如下:

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=D:\\java\\zookeeper-data\\3.4.6-data# the port at which the clients will connectclientPort=2181# the maximum number of client connections.# increase this if you need to handle more clients#maxClientCnxns=60## Be sure to read the maintenance section of the # administrator guide before turning on autopurge.## http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain in dataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable auto purge feature#autopurge.purgeInterval=1

然後雙擊bin目錄下的zkServer.cmd即可啟動zookeeper:

zookeeper啟動後如,預設佔用的連接埠號碼為2181:

 

(6)下載kafka源碼。從kafka官網下載源碼包kafka-0.10.0.1-src.tgz,解壓,比如我解壓到了D:\kafka-0.10.0.1-src目錄下,在解壓後的目錄下面通過命令列視窗執行gradle idea命令,然後經過漫長的等待,控制台會出現構建成功的提示,說明kafka源碼編譯完成;

 

 (7)開發工具使用的是IntellJ IDEA 14.1.7(也可以使用其他更高的版本):

(8)在IntelliJ IDEA中安裝scala外掛程式,這裡我安裝的外掛程式版本為 1.5.4:

 

(9)將編譯好的kafka源碼匯入到idea開發工具中,匯入後的目錄情況:

 

(10)將config目錄下的log4j.properties檔案拷貝到core\src\main\scala\目錄下,方便查看日誌:

(11) 修改server.properties檔案中的log.dirs=D:\\tmp\\kafka-logs(修改為你自己windows磁碟目錄)

(12)啟動kafka伺服器,即運行core\src\main\scala\kafka\Kafka.scala中的main方法,運行前指定啟動參數:

(13)啟動生產者,啟動參數配置:

 

(14)啟動消費者,啟動參數配置:

 

 (15)在生產者的控制台上輸入訊息"hello kafka"並斷行符號:

 

觀察消費者的控制台上,如果有訊息被消費,說明源碼環境搭建成功:

 

致此,kafka在IntelliJ IDEA中的源碼環境搭建成功。

 

windows下IntelliJ IDEA搭建kafka源碼環境

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.