我正在使用 HTTP 源将 JSON 文件放入 HDFS(单节点 SANDBOX)。
文件在正确的目录中创建,但没有任何内容附加到文件中。在我开始调试 HTTP 源之前,你能验证我的 flume.conf 吗?
#################################################################
# Name the components on this agent
#################################################################
hdfs-agent.sources = httpsource
hdfs-agent.sinks = hdfssink
hdfs-agent.channels = channel1
#################################################################
# Describe source
#################################################################
# Source node
hdfs-agent.sources.httpsource.type = http
hdfs-agent.sources.httpsource.port = 5140
hdfs-agent.sources.httpsource.handler = org.apache.flume.source.http.JSONHandler
#################################################################
# Describe Sink
#################################################################
# Sink hdfs
hdfs-agent.sinks.hdfssink.type = hdfs
hdfs-agent.sinks.hdfssink.hdfs.path = hdfs://sandbox:8020/user/flume/node
hdfs-agent.sinks.hdfssink.hdfs.fileType = DataStream
hdfs-agent.sinks.hdfssink.hdfs.batchSize = 1
hdfs-agent.sinks.hdfssink.hdfs.rollSize = 0
hdfs-agent.sinks.hdfssink.hdfs.rollCount = 0
#################################################################
# Describe channel
#################################################################
# Channel memory
hdfs-agent.channels.channel1.type = memory
hdfs-agent.channels.channel1.capacity = 1000
hdfs-agent.channels.channel1.transactionCapacity = 100
#################################################################
# Bind the source and sink to the channel
#################################################################
hdfs-agent.sources.httpsource.channels = channel1
hdfs-agent.sinks.hdfssink.channel = channel1
我目前只是尝试从小处着手来测试它:
[{"text": "Hi Flume this Node"}]
所以我认为我的 batchSize/rollSize/rollCount 可能是这里的问题?
最佳答案
batchSize、rollSize、rollCount 值都可以。 将 rollSize 和 rollCount 设置为 0 将禁用文件滚动功能。
hdfs-agent.sources.httpsource.type 应设置为 org.apache.flume.source.http.HTTPSource
发送到http源的数据格式应该是
[{"headers": {"a":"b", "c":"d"},"body": "random_body"}, {"headers": {"e": "f"},"body": "random_body2"}].
我测试了使用您使用的数据发送 ([{"text": "Hi Flume this Node"}])。由于没有“正文”属性,因此没有任何内容附加到我的文件中。但是当我发布以下内容时,数据已附加到我的文件中。
curl -X POST -H 'Content-Type: application/json; charset=UTF-8' -d '[{ "headers" : { "timestamp" : "434324343", "host" :"random_host.example.com", "field1" : "val1" }, "body" : "random_body" }]' http://localhost:5140.
希望对你有帮助
关于hadoop - 在 HDFS 中创建文件但不附加任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29201502/