Spring Cloud Dataflow - http |卡夫卡和卡夫卡| hdfs - 在HDFS中获取原始消息

问题描述 投票:0回答:1

我在SCDF(本地服务器1.7.3)中创建基本流,其中我正在配置2个流。 1. HTTP - > Kafka主题2. Kafka主题 - > HDFS

流:

stream create --name ingest_from_http --definition "http --port=8000 --path-pattern=/test > :streamtest1"
stream deploy --name ingest_from_http --properties "app.http.spring.cloud.stream.bindings.output.producer.headerMode=raw"

stream create --name ingest_to_hdfs --definition ":streamtest1 > hdfs --fs-uri=hdfs://<host>:8020 --directory=/tmp/hive/sensedev/streamdemo/ --file-extension=xml --spring.cloud.stream.bindings.input.consumer.headerMode=raw" 

我在位置/ tmp / hive / sensedev / streamdemo /上创建了一个Hive托管表

DROP TABLE IF EXISTS gwdemo.xml_test;
CREATE TABLE gwdemo.xml_test(

id int,

name string

 )

ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'

WITH SERDEPROPERTIES (

"column.xpath.id"="/body/id/text()",

"column.xpath.name"="/body/name/text()"


)

STORED AS

INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'

OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'

LOCATION '/tmp/hive/sensedev/streamdemo'

TBLPROPERTIES (

"xmlinput.start"="<body>",

"xmlinput.end"="</body>")

;

测试:

  1. Hive是否能够读取XML:将xml文件放在/ tmp / hive / sensedev / streamdemo位置。

文件内容:<body><id>1</id><name>Test1</name></body>

在表上运行SELECT命令时,它正确显示上述记录。

  1. 当使用http post在SCDF中发布记录时,我在Kafka Consumer中获得了正确的数据,但是当我检查HDFS时,正在创建xml文件,但我在这些文件中接收原始消息。例: dataflow> http post --target http:/// test --data“<body><id>2</id><name>Test2</name></body>”--contentType application / xml

在Kafka Console Consumer中,我能够阅读正确的XML消息:<body><id>2</id><name>Test2</name></body>

 $ hdfs dfs -cat /tmp/hive/sensedev/streamdemo/hdfs-sink-2.xml
[B@31d94539

问题:1。我错过了什么?如何在HDFS中新创建的XML文件中获取正确的XML记录?

hadoop hive apache-kafka hdfs spring-cloud-dataflow
1个回答
0
投票

HDFS Sink需要一个Java Serialized对象。

© www.soinside.com 2019 - 2024. All rights reserved.