1. 程式人生 > >flume1.7原始碼編譯及main方法啟動

flume1.7原始碼編譯及main方法啟動

一、編譯
首先下載flume1.7原始碼,匯入eclipse

1.Maven依賴報錯Missing artifact jdk.tools:jdk.tools:jar:1.7

新增依賴

<dependency>  
    <groupId>jdk.tools</groupId>  
    <artifactId>jdk.tools</artifactId>  
    <version>1.7</version>  
    <scope>system</scope>  
    <systemPath
>
${JAVA_HOME}/lib/tools.jar</systemPath> </dependency>

2.eclipse校驗提示錯誤
這裡寫圖片描述

原因:AvroFlumeEvent類是編譯生成的,eclipse依賴找不到正常,沒影響

3.執行
mvn install -Dmaven.test.skip=true -Dtar

編譯成功後會在flume-ng-dist/target下生成tar包
這裡寫圖片描述

4.倉庫不全的話有些包下不到需手動新增,也可以直接註釋不需要的外掛依賴
手動新增方法:

  • 執行 mvn install:install-file -Dfile=E:\xxx\xxx.jar -DgroupId=xxx
    -DartifactId=xxx -Dversion=xxx -Dpackaging=jar

二、啟動
1.flume-ng-node根目錄下建立test.properties

# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
a1.sources.r1.channels = c1 # Describe the sink a1.sinks.k1.type = logger a1.sinks.k1.channel = c1 # Use a channel which buffers events in memory a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100

2.建立src/main/resources資原始檔夾,複製根目錄conf下log4j檔案放進去,修改日誌級別
這裡寫圖片描述

3.設定Application執行引數 -n a1 -f test.properties
這裡寫圖片描述

4.啟動Application
使用telnet命令就可以測試了

5.啟動可能報錯沒有相關類

原因:flume-ng-node預設依賴可能不包括該外掛
比如kafka sink需在pom.xml增加依賴

    <dependency>
      <groupId>org.apache.flume.flume-ng-sinks</groupId>
      <artifactId>flume-ng-kafka-sink</artifactId>
    </dependency>