エクスポート用Sink Connector
Sink Connectorを使用して、Kafkaのトピックからデータベース、データレイク、その他の送信先へデータをエクスポートする方法を学習します。
「エクスポート用Sink Connector」はCoddyKit上の無料Apache Kafka & Stream Processing Fundamentalsレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはApache Kafka & Stream Processing Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Apache Kafka & Stream Processing Fundamentalsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Exporting Data from Kafka
Welcome to the final lesson on Kafka Connect! We've learned how to bring data into Kafka using Source Connectors. Now, let's explore how to get data out.
This lesson focuses on Sink Connectors, which are essential for moving data from your Kafka topics to external systems like databases, data warehouses, or analytics platforms.
Why Use Sink Connectors?
Imagine you have real-time data streaming into Kafka, but your business intelligence tools or legacy applications need that data in a different system.
- Integration: Connect Kafka to almost any data store.
- No Custom Code: Avoid writing complex consumer applications for common destinations.
- Reliability: Built-in fault tolerance and delivery guarantees.
- Scalability: Easily scale data export by adding more connector tasks.
How Sink Connectors Function
A Sink Connector acts like a specialized Kafka consumer. Here's the basic workflow:
- The connector runs within a Kafka Connect worker.
- It subscribes to one or more Kafka topics.
- It consumes messages from these topics.
- It transforms (if configured) and writes the data to the target external system.
- It manages Kafka offsets, ensuring data is processed reliably.
Common Sink Destinations
Kafka Connect offers a rich ecosystem of pre-built sink connectors for a wide variety of destinations. Some popular examples include:
- Databases: PostgreSQL, MySQL, Oracle, SQL Server (via JDBC)
- Cloud Storage: Amazon S3, Google Cloud Storage, Azure Blob Storage
- Search Engines: Elasticsearch, Solr
- Data Warehouses: Snowflake, Redshift
- Other Systems: HDFS, JMS queues, HTTP endpoints
Basic Sink Connector Configuration
Configuring a sink connector is similar to source connectors. You define its properties in a JSON file or directly via the Connect REST API. Key properties include:
name: Unique name for your connector.connector.class: The specific connector implementation (e.g.,JdbcSinkConnector).topicsortopics.regex: The Kafka topics to read from.key.converter&value.converter: How to deserialize data from Kafka.
Example: FileStreamSinkConnector
Let's look at a simple example: the FileStreamSinkConnector. This built-in connector writes data from a Kafka topic to a local file. It's great for observing how sink connectors work.
Here's a basic configuration JSON for it:
{ "name": "file-sink-connector",
"config": {
"connector.class": "org.apache.kafka.connect.file.FileStreamSinkConnector",
"tasks.max": "1",
"topics": "my_test_topic",
"file": "/tmp/kafka-sink-output.txt",
"key.converter": "org.apache.kafka.connect.storage.StringConverter",
"value.converter": "org.apache.kafka.connect.storage.StringConverter"
}
}Deploying a Sink Connector
Once you have your connector configuration (like the file-sink-config.json above), you deploy it to your Kafka Connect cluster using a curl command against the Connect REST API:
This command tells the Connect cluster to create and start a new connector instance based on your configuration.
curl -X POST -H "Content-Type: application/json" \
--data @file-sink-config.json \
http://localhost:8083/connectorsData Formats and Converters
When a sink connector reads data from Kafka, it uses converters to deserialize the message keys and values. Common converters include:
StringConverter: For plain text data.JsonConverter: For JSON formatted data.AvroConverter: For Avro-serialized data (often with Schema Registry).
The connector then takes this deserialized data and formats it appropriately for the target system (e.g., SQL INSERT statements for a database sink).
Ensuring Data Integrity
Kafka Connect sink connectors are designed for reliability:
- At-Least-Once Delivery: Most sink connectors guarantee that each message will be delivered to the destination at least once, even if failures occur.
- Offset Management: Connectors automatically commit offsets to Kafka, tracking what data has been successfully processed.
- Error Handling: Connectors can be configured to retry failed operations or send problematic messages to a Dead Letter Queue (DLQ) for later inspection.
Sink Connector Challenge
Let's check your understanding of Kafka Connect Sink Connectors!
Recap: Sink Connectors
Great job! You've now grasped the core concepts of Kafka Connect Sink Connectors.
- Sink Connectors export data from Kafka topics to various external systems.
- They provide a reliable, scalable, and code-free way to integrate Kafka with your data ecosystem.
- Configuration involves specifying the connector class, topics, and destination-specific properties.
- They handle data deserialization, formatting, and ensure delivery guarantees.
Kafka Connect significantly simplifies building robust data pipelines!
AI チューターと学ぶ Apache Kafka & Stream Processing Fundamentals — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「エクスポート用Sink Connector」レッスンは無料ですか?
はい。「エクスポート用Sink Connector」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Apache Kafka & Stream Processing Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Apache Kafka & Stream Processing Fundamentalsコースには全4レッスンが含まれています。
「エクスポート用Sink Connector」で何を学びますか?
Sink Connectorを使用して、Kafkaのトピックからデータベース、データレイク、その他の送信先へデータをエクスポートする方法を学習します。 ブラウザで直接実行するハンズオンコードでApache Kafka & Stream Processing Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Apache Kafka & Stream Processing Fundamentalsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのApache Kafka & Stream Processing Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「エクスポート用Sink Connector」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このApache Kafka & Stream Processing Fundamentalsレッスンでコードを書いて実行できますか?
はい。すべてのApache Kafka & Stream Processing Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Kafka Connect入門
- 取り込み用Source Connector
- エクスポート用Sink Connector
- 単一メッセージ変換(SMT)