1.3 Quick Start中 Step 7: Use Kafka Connect to import/export data官网剖析(博主推荐)

简介:

  一切来源于官网

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

 

 

 

 

 

 

 

 

Step 7: Use Kafka Connect to import/export data

Step 7: 使用 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.

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

 



本文转自大数据躺过的坑博客园博客,原文链接:http://www.cnblogs.com/zlslch/p/6767386.html,如需转载请自行联系原作者

相关文章
|
消息中间件 存储 NoSQL
一文读懂Kafka Connect核心概念
Kafka Connect 是一种用于在 Apache Kafka 和其他系统之间可扩展且可靠地流式传输数据的工具。 它使快速定义将大量数据移入和移出 Kafka 的连接器变得简单。 Kafka Connect 可以摄取整个数据库或从所有应用程序服务器收集指标到 Kafka 主题中,使数据可用于低延迟的流处理。 导出作业可以将数据从 Kafka 主题传送到二级存储和查询系统或批处理系统进行离线分析。
|
消息中间件 分布式计算 Hadoop
kafka connect,将数据批量写到hdfs完整过程
版权声明:本文为博主原创文章,未经博主允许不得转载 本文是基于hadoop 2.7.1,以及kafka 0.11.0.0。kafka-connect是以单节点模式运行,即standalone。   一. 首先,先对kafka和kafka connect做一个简单的介绍   kafka:Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据。
2139 0
|
4月前
|
消息中间件 关系型数据库 MySQL
在kafka connect 同步 mysql 主从数据库
在kafka connect 同步 mysql 主从数据库
45 0
|
4月前
|
消息中间件 Kafka Windows
使用Kafka Connect 导入导出数据
使用Kafka Connect 导入导出数据
75 0
|
4月前
|
消息中间件 关系型数据库 MySQL
Kafka Connect :构建强大分布式数据集成方案
Kafka Connect 是 Apache Kafka 生态系统中的关键组件,专为构建可靠、高效的分布式数据集成解决方案而设计。本文将深入探讨 Kafka Connect 的核心架构、使用方法以及如何通过丰富的示例代码解决实际的数据集成挑战。
|
6月前
|
消息中间件 存储 Kafka
Apache Kafka - 构建数据管道 Kafka Connect
Apache Kafka - 构建数据管道 Kafka Connect
101 0
|
6月前
|
消息中间件 JSON 关系型数据库
[实战系列]SelectDB Cloud Kafka Connect 最佳实践张家锋
[实战系列]SelectDB Cloud Kafka Connect 最佳实践张家锋
94 1
|
10月前
|
消息中间件 JSON 监控
实时数据同步与共享:使用Apache Kafka Connect
在现代应用程序开发中,实时数据同步和共享变得越来越重要。而Apache Kafka Connect作为一个可靠的、分布式的数据集成工具,为我们提供了一种简单而强大的方式来实现实时数据的传输和共享。
576 0
|
消息中间件 JSON Java
替代Flume——Kafka Connect简介
替代Flume——Kafka Connect简介
366 0
替代Flume——Kafka Connect简介
|
消息中间件 存储 弹性计算
基于Kafka connect+函数计算的轻量计算解决方案
Kafka ETL基于kafka connect加函数计算,为云上用户提供了一套数据流转加数据计算的一站式解决方案。
665 0

热门文章

最新文章