简体   繁体   English

Kafka Connect-在写入HDFS接收器之前修改记录

[英]Kafka Connect- Modifying records before writing into HDFS sink

I have installed Kafka connect using confluent-4.0.0 Using hdfs connector I am able to save Avro records received from Kafka topic to hive. 我已经使用confluent-4.0.0安装了Kafka connect。使用hdfs连接器,我可以将从Kafka主题收到的Avro记录保存到配置单元中。 I would like to know if there is any way to modify the records before writing into hdfs sink. 我想知道在写入hdfs接收器之前是否有任何方法可以修改记录。 My requirement is to do small modifications to values of the record. 我的要求是对记录的值做一些小的修改。 For Example, performing arithmetic operations on integers or manipulation of strings etc. Please suggest if there any way to achieve this 例如,对整数执行算术运算或对字符串进行操作等。请建议是否有任何方法可以实现此目的

You have several options. 您有几种选择。

  1. Single Message Transforms , which you can see in action here . 单个消息转换 ,您可以在此处查看实际操作。 Great for light-weight changes as messages pass through Connect. 当消息通过Connect传递时,非常适合轻量级更改。 Configuration-file based, and extensible using the provided API if there's not an existing transform that does what you want. 基于配置文件,并且可以使用提供的API进行扩展,如果没有现有的转换可以满足您的要求。

    See the discussion here on when SMT are suitable for a given requirement. 请参见此处有关SMT何时适合给定要求的讨论。

  2. KSQL is a streaming SQL engine for Kafka. KSQL是Kafka的流式SQL引擎。 You can use it to modify your streams of data before sending them to HDFS. 您可以使用它来修改数据流,然后再将其发送到HDFS。 See this example here . 在这里看到这个例子

  3. KSQL is built on the Kafka Stream's API , which is a Java library and gives you the power to transform your data as much as you'd like. KSQL建立在Kafka Stream的API上 ,该API是Java库,可让您随意转换数据。 Here's an example . 这是一个例子

Take a look at Kafka connect transformers [1] & [2]. 看一下Kafka连接变压器[1]和[2]。 You can build a custom transformer library and use it in connector. 您可以构建自定义转换器库,并在连接器中使用它。

[1] http://kafka.apache.org/documentation.html#connect_transforms [2] https://cwiki.apache.org/confluence/display/KAFKA/KIP-66%3A+Single+Message+Transforms+for+Kafka+Connect [1] http://kafka.apache.org/documentation.html#connect_transforms [2] https://cwiki.apache.org/confluence/display/KAFKA/KIP-66%3A+Single+Message+Transforms+for +卡夫卡+连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM