kafka---->kafka connect的使用(一)

  这里面介绍一下kafka connect的一些使用。

 

kafka connect的使用

一、在config目录下面复制一个file-srouce.properties并且修改内容

huhx@gohuhx:~/server/kafka_2.11-1.1.0/config$ cp connect-file-source.properties connect-file-source-test.properties
huhx@gohuhx:~/server/kafka_2.11-1.1.0/config$ cp connect-standalone.properties connect-standalone-test.properties

修改huhx目录下面的connect-standalone-test.properties文件里面的内容如下:

key.converter.schemas.enable=false
value.converter.schemas.enable=false

connect-file-source-test.properties的内容如下:

name=local-file-source
connector.class=FileStreamSource
tasks.max=1
file=/home/huhx/Documents/linux.txt
topic=connect-linux

transforms=MakeMap, InsertSource
transforms.MakeMap.type=org.apache.kafka.connect.transforms.HoistField$Value
transforms.MakeMap.field=line
transforms.InsertSource.type=org.apache.kafka.connect.transforms.InsertField$Value
transforms.InsertSource.static.field=data_source
transforms.InsertSource.static.value=test-file-source

指定了topic为connect-test,指定了读取的文件为/home/huhx/Documents/linux.txt。其中linux.txt的内容如下

I love you.
my name is huhx.
code for me?

 

二、运行connect-standalone.sh命令,可以将对huhx.txt文件处理之后的内容发布到connect-test的topic上

huhx@gohuhx:~/server/kafka_2.11-1.1.0$ bin/connect-standalone.sh config/connect-standalone-test.properties config/connect-file-source-test.properties

运行之后,我们在connect-test主题里面可以看到如下的输出:

huhx@gohuhx:~/server/kafka_2.11-1.1.0$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092     --topic connect-linux    --from-beginning
{"line":"I love you.","data_source":"test-file-source"}
{"line":"my name is huhx.","data_source":"test-file-source"}
{"line":"code for me?","data_source":"test-file-source"}

关于上述配置的transforms可以参考下述的文档https://kafka.apache.org/documentation/#connect

 

友情链接

 

转载于:https://www.cnblogs.com/huhx/p/baseusekafkaconnect1.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值