使用 cURL 并手动添加时间戳测试 Flume HDFS 接收器和 netcat 源

Test Flume HDFS sink and netcat source using cURL and manually adding timestamp

我有以下flume配置

tier1.sources.source1.type     = netcat 
tier1.sources.source1.bind     = 199.9.0.11
tier1.sources.source1.port     = 9999
tier1.sources.source1.channels = channel1 
tier1.channels.channel1.type   = memory 

tier1.sinks.sink1.type         = hdfs 
tier1.sinks.sink1.channel      = channel1 
tier1.sinks.sink1.hdfs.path  = /flume/events/%y-%m-%d/%H%M/%S 
tier1.sinks.sink1.hdfs.filePrefix = events- 

如何使用 cURL 手动指定 时间戳来测试它?

我尝试了以下不同的变体:

curl -H 'timestamp : 1471620532' --data 'test' telnet://199.9.0.11:9999

我尝试的一切都以 Flume 日志中的错误告终:

Expected timestamp in the Flume event headers, but it was null

所有解决方案都让您设置 hdfs.useLocalTimeStamp = true 和/或使用拦截器。

如果源不一定是netcat,那么我建议使用HTTP Source

在那里你可以指定任何 headers,除此之外它可以与 netcat 源非常相似地使用。

对于示例配置,您可以尝试

a1.sources = r1
a1.channels = c1
a1.sources.r1.type = http
a1.sources.r1.port = 5140
a1.sources.r1.channels = c1

a1.channels = c1
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 10000
a1.channels.c1.byteCapacityBufferPercentage = 20
a1.channels.c1.byteCapacity = 800000

a1.channels = c1
a1.sinks = k1
a1.sinks.k1.type = logger
a1.sinks.k1.channel = c1