嘗試flume配置文件從啓動命令接收參數

接着上一篇flume接收數據傳入hbase。
這次的目的是:
flume配置文件sink指定hbase的表名可以當成參數進行接收,以便於能隨外部切換hbase不同的表。
例如在test.conf中

a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = http
a1.sources.r1.port = 44444
a1.sources.r1.bind = 10.0.0.183

# Describe the sink
a1.sinks.k1.type = hbase
a1.sinks.k1.channel = c1
#a1.sinks.k1.table = httpdata
a1.sinks.k1.table = ${htable}   #傳入表名
a1.sinks.k1.columnFamily = a
a1.sinks.k1.serializer = com.hbase.Rowkey
a1.sinks.k1.channel = memoryChannel

# Use a channel which buffers events in memory
a1.channels.c1.type = file
a1.channels.c1.checkpointDir = /home/mathartsys/oyzm_test/flu-hbase/checkpoint/
a1.channels.c1.useDualCheckpoints = false
a1.channels.c1.dataDirs = /home/mathartsys/oyzm_test/flu-hbase/flumedir/
a1.channels.c1.maxFileSize = 2146435071
a1.channels.c1.capacity = 100000
a1.channels.c1.transactionCapacity = 10000

# Bind the source and sink to the channel
a1.sources.r1.channels = c1 
a1.sinks.k1.channel = c1

嘗試了兩種傳參方法:
1.從flume命令中攜帶變量參數進入test.conf中
官網外部傳參示例:
配置:

a1.sources = r1
a1.sources.r1.type = netcat
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = ${NC_PORT}
a1.sources.r1.channels = c1

啓動命令:

NC_PORT=44444 bin/flume-ng agent –conf conf –conf-file example.conf –name a1 -Dflume.root.logger=INFO,console -DpropertiesImplementation=org.apache.flume.node.EnvVarResolverProperties

實際上如果在配置文件中配置了sink和channels後,外部參數是無法傳入的,
報錯提示:
java.lang.NumberFormatException: For input string: “${NC_PORT}”

2.通過flume中的正則攔截器interceptors( regex_extractor)接收hbase表名
source和sink的配置

a1.sources.r1.interceptors = i1  
a1.sources.r1.interceptors.i1.type = regex_extractor
a1.sources.r1.interceptors.i1.regex = (\\d)
a1.sources.r1.interceptors.i1.serializers = s1
a1.sources.r1.interceptors.i1.serializers.s1.name = table

a1.sinks.k1.type = hbase
a1.sinks.k1.channel = c1
a1.sinks.k1.table = ${s1}
a1.sinks.k1.columnFamily = cf
a1.sinks.k1.serializer = com.hbase.Rowkey
a1.sinks.k1.channel = memoryChannel 

寫入命令

curl -X POST -d'[{"body":"1"}]'  http://10.0.0.183:44444

報錯:Illegal character code:36, <$> at 0. User-space table qualifiers can only contain ‘alphanumeric characters’: i.e. [a-zA-Z_0-9-.]: ${s1}
原因:在.conf配置文件啓動後,sinks會直接去連接指定的hbase表。如果想要更換表,只能是重新啓動新的conf配置文件

結論:實現flume配置靈活指定hbase表名失敗

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章