不多说,直接上干货!

  一切来源于官网

http://kafka.apache.org/documentation/

Step 7: Use Kafka Connect to import/export data

Step : 使用 Kafka Connect 来 导入/导出 数据

  Writing data from the console and writing it back to the console is a convenient place to start, but you'll probably want to use data from other sources or export data from Kafka to other systems. For many systems, instead of writing custom integration code you can use Kafka Connect to import or export data.

从控制台写入和写回数据是一个方便的开始,但你可能想要从其他来源导入或导出数据到其他系统。
对于大多数系统,可以使用kafka Connect,而不需要编写自定义集成代码。

  Kafka Connect is a tool included with Kafka that imports and exports data to Kafka. It is an extensible tool that runs connectors, which implement the custom logic for interacting with an external system. In this quickstart we'll see how to run Kafka Connect with simple connectors that import data from a file to a Kafka topic and export data from a Kafka topic to a file.

Kafka Connect是导入和导出数据的一个工具。它是一个可扩展的工具,运行连接器,实现与自定义的逻辑的外部系统交互。
在这个快速入门里,
我们将看到如何运行Kafka Connect用简单的连接器从文件导入数据到Kafka主题,
再从Kafka主题导出数据到文件

  First, we'll start by creating some seed data to test with:

首先,我们首先创建一些种子数据用来测试:
> echo -e "foo\nbar" > test.txt


  Next, we'll start two connectors running in standalone mode, which means they run in a single, local, dedicated process. We provide three configuration files as parameters. The first is always the configuration for the Kafka Connect process, containing common configuration such as the Kafka brokers to connect to and the serialization format for data. The remaining configuration files each specify a connector to create. These files include a unique connector name, the connector class to instantiate, and any other configuration required by the connector.

接下来,我们开启2个连接器运行在独立的模式,这意味着它们运行在一个单一的,本地的,专用的进程。
我们提供3个配置文件作为参数。
第一个始终是kafka Connect进程,如kafka broker连接和数据库序列化格式,
剩下的配置文件每个指定的连接器来创建,这些文件包括一个独特的连接器名称,连接器类来实例化和任何其他配置要求的。
> bin/connect-standalone.sh   config/connect-standalone.properties   config/connect-file-source.properties   config/connect-file-sink.properties


  These sample configuration files, included with Kafka, use the default local cluster configuration you started earlier and create two connectors: the first is a source connector that reads lines from an input file and produces each to a Kafka topic and the second is a sink connector that reads messages from a Kafka topic and produces each as a line in an output file.

这是示例的配置文件,使用默认的本地集群配置并创建了2个连接器:
第一个是导入连接器,从导入文件中读取并发布到Kafka主题,
第二个是导出连接器,从kafka主题读取消息输出到外部文件

  During startup you'll see a number of log messages, including some indicating that the connectors are being instantiated. Once the Kafka Connect process has started, the source connector should start reading lines from test.txt and producing them to the topic connect-test, and the sink connector should start reading messages from the topic connect-test and write them to the file test.sink.txt. We can verify the data has been delivered through the entire pipeline by examining the contents of the output file:

在启动过程中,你会看到一些日志消息,包括一些连接器实例化的说明。
一旦kafka Connect进程已经开始,导入连接器应该读取从test.txt和写入到topic connect-test,导出连接器从主题connect-test读取消息写入到文件test.sink.txt
. 我们可以通过验证输出文件的内容来验证数据数据已经全部导出:
> cat test.sink.txt
foo
bar

  Note that the data is being stored in the Kafka topic connect-test, so we can also run a console consumer to see the data in the topic (or use custom consumer code to process it):

注意,导入的数据也已经在Kafka主题connect-test里,所以我们可以使用该命令查看这个主题:
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic connect-test --from-beginning
{"schema":{"type":"string","optional":false},"payload":"foo"}
{"schema":{"type":"string","optional":false},"payload":"bar"}
...

  The connectors continue to process data, so we can add data to the file and see it move through the pipeline:

连接器继续处理数据,因此我们可以添加数据到文件并通过管道移动:
> echo "Another line" >> test.txt


  You should see the line appear in the console consumer output and in the sink file.

你应该会看到出现在消费者控台输出一行信息并导出到文件。

1.3 Quick Start中 Step 7: Use Kafka Connect to import/export data官网剖析(博主推荐)的更多相关文章

  1. 1.3 Quick Start中 Step 8: Use Kafka Streams to process data官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 8: Use Kafka Streams to process data ...

  2. 1.3 Quick Start中 Step 6: Setting up a multi-broker cluster官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 6: Setting up a multi-broker cluster ...

  3. 1.3 Quick Start中 Step 4: Send some messages官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 4: Send some messages Step : 发送消息 Kaf ...

  4. 1.3 Quick Start中 Step 2: Start the server官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 2: Start the server Step : 启动服务 Kafka ...

  5. 1.3 Quick Start中 Step 5: Start a consumer官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 5: Start a consumer Step : 消费消息 Kafka ...

  6. 1.3 Quick Start中 Step 3: Create a topic官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 3: Create a topic Step 3: 创建一个主题(topi ...

  7. 1.1 Introduction中 Kafka for Stream Processing官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka for Stream Processing kafka的流处理 It i ...

  8. 1.1 Introduction中 Kafka as a Storage System官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka as a Storage System kafka作为一个存储系统 An ...

  9. 1.1 Introduction中 Kafka as a Messaging System官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Kafka as a Messaging System kafka作为一个消息系统 ...

随机推荐

  1. 一个最不可思议的MySQL死锁分析

    1    死锁问题背景    1 1.1    一个不可思议的死锁    1 1.1.1    初步分析    3 1.2    如何阅读死锁日志    3 2    死锁原因深入剖析    4 2. ...

  2. java 究竟老年代和年轻代的比例为多大合适呢?

    眼下我还没有这方面过多的经验,和切身体会 只是以我眼下的水平看来,年轻代不宜大,假设年轻代大会导致转为老年代的时候,老年代撑不下.导致full gc.回收停顿时间过长

  3. Ubuntu14环境下minigui安装问题记录--object.lo错误

    minigui3.0.12在Ubuntu14上面编译只是去?出现这个错误:object.h:275:9: error: incompatible types when assigning to typ ...

  4. 添加使用session回话属性

    @SessionAttributes("nowUser") nowUser :id/userName/password public String delectMsg(int id ...

  5. POJ 3189 二分+Dinic

    题意: 思路: 二分跨度 枚举最低座次 建图:源点向每头牛连边权为1的边 每头牛向当前枚举的B的区间这段连上边权为1的边 所有座次向汇点连边权为牛棚容量的边 判判流量是不是等于n 一开始写得是直接枚举 ...

  6. C# double保留四位小数

    2.保留N位,四舍五入 . decimal d= decimal.Round(decimal.Parse("0.55555"),4); 3.保留N位四舍五入 Math.Round( ...

  7. K-序列(埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛)

    题目描述 给一个数组 a,长度为 n,若某个子序列中的和为 K 的倍数,那么这个序列被称为“K 序列”.现在要你 对数组 a 求出最长的子序列的长度,满足这个序列是 K 序列.  输入描述: 第一行为 ...

  8. 电脑无法上网,DHCP客户端不能正确获取IP地址

    问题特征:DHCP服务器更新[保留]配置信息后,给一客户端绑定了新的IP地址;但客户端IP地址并未正确更新; 处理: 一.检查DHCP服务器配置; 1.MAC地址.IP地址均正确;并已“添加到筛选器” ...

  9. 实现人脸识别性别之路---matplotlib之注释

    一.准备数据 利用np.linspace()函数得到一定范围内的数据集 利用2*x+1的公式求出y 二.创建窗口 三.根据具有规律的数据画图 四.调整坐标轴 1.将原本的坐标轴的上轴和右轴去掉,使用基 ...

  10. codeforces 140E.New Year Garland

    传送门: 解题思路: 要求相邻两行小球颜色集合不同,并且限制行内小球相邻不同. 由此可得:每行小球排列都是独立与外界的, 所以答案应该是对于所有行的颜色集合分类,在将行内的答案乘到上面. 先考虑如何分 ...