使用kafka connect将文本文件数据导入到kafka

一 实验目的

将/opt/a.txt文件内容导入到kafka的test主题里。

[root@Centos7-Mode-V7 opt]# cat /opt/a.txt

hello

world

二 实验步骤

2.1 配置connect-file-source.properties

vi /opt/kafka/config/connect-file-source.properties

修改file为要导入的文件,topic为目标topic。

示例:

name=local-file-source

connector.class=FileStreamSource

tasks.max=1

file=/opt/a.txt

topic=test

2.2 导入数据

cd /opt/kafka

bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties

2.3 验证数据是否导入成功

cd /opt/kafka

[root@Centos7-Mode-V7 kafka]# bin/kafka-console-consumer.sh  -bootstrap-server 192.168.144.206:9092 --topic test --from-beginning

{"schema":{"type":"string","optional":false},"payload":"hello"}

{"schema":{"type":"string","optional":false},"payload":"world"}

猜你喜欢

转载自blog.csdn.net/yabignshi/article/details/111982765