hadoop - 在 HDFS 中创建文件但不附加任何内容

标签 hadoop cloudera flume hortonworks-data-platform flume-ng

我正在使用 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/

相关文章:

scala - Spark 提交成功运行,但通过 oozie 提交时无法连接到配置单元

apache-kafka - 如何在不指定源的情况下使用 Flume 的 Kafka Channel

hadoop - Flume 以不一致的方式接收数据

java - Apache Flume/var/log/flume-ng/flume.log(权限被拒绝)

apache-spark - 超过 yarn throw 最大递归深度时, Spark 提交pyspark脚本

scala - 转换 RDD 中的字符串集合

java - 第二次迭代 - 值保持不变

java - 使用Java将一个reducer的输出提供给另一个reducer的示例代码片段示例

hadoop - 如何在配置单元中进行数据库备份?我的意思是 Hive 数据库备份

java - 使用 Apache Lucene 进行搜索优化