我在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>")
;
测试:
文件内容:<body><id>1</id><name>Test1</name></body>
在表上运行SELECT命令时,它正确显示上述记录。
<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记录?
HDFS Sink需要一个Java Serialized对象。