这里面介绍一下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=
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.-1.1.$ bin/connect-standalone.sh config/connect-standalone-test.properties config/connect-file-source-test.properties

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

huhx@gohuhx:~/server/kafka_2.-1.1.$ bin/kafka-console-consumer.sh --bootstrap-server localhost:     --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

友情链接

最新文章

  1. Ubuntu菜鸟入门(六)—— 有道词典安装
  2. 钉钉js依赖库学习
  3. NSURLSessionTask使用dispatch_semaphore 完成同步机制
  4. HOG matlab练习
  5. 获取select值
  6. Android Blur效果之FastBlur
  7. every();some();filter();map();forEach()各自区别:
  8. 如何用Python写一个计算器软件 附带效果图
  9. noi 2016 游记
  10. ios开发-将false和true,当做字典的值,并将字典转成字符串,上传到服务器
  11. js判断时间是否超过了16:30
  12. 如何组织AxTOCControl里面的数据
  13. React相关:npm,ES6,
  14. 如何利用iconfont图标代替小图片
  15. Python基础04_str_方法
  16. Spring-json依赖
  17. 关于webpack的path和publicPath。
  18. spark(一)
  19. MD5的各种实现——也是醉了
  20. C#去边框以及无边框窗体移动

热门文章

  1. gravity 和 layout_gravity
  2. 异常处理汇总 ~ 修正果带着你的Code飞奔吧!
  3. Linux中的普通命令如何以管理员身份运行
  4. Python计算分位数
  5. Mac上搭建ELK
  6. 什么是ip代理
  7. C#读取Excel文件的简单方法
  8. 分析技术和方法论营销理论知识框架,营销方面4P、用户使用行为、STP,管理方面5W2H、逻辑树、金字塔、生命周期
  9. MySQL技术内幕读书笔记(七)——锁
  10. Fluent动网格【9】:区域运动