ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า
เรียนรู้การกำหนดค่าและนำตัวเชื่อมต่อแหล่งข้อมูลไปใช้งาน เพื่อนำเข้าข้อมูลจากฐานข้อมูล ไฟล์ และแหล่งข้อมูลอื่นเข้าสู่ Kafka
ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า เป็นบทเรียน Apache Kafka & Stream Processing Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Apache Kafka & Stream Processing Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Apache Kafka & Stream Processing Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Data Ingestion with Connectors
Welcome! In this lesson, we'll dive into Source Connectors, a powerful feature of Kafka Connect.
Source connectors are like bridges. They help you bring data from external systems, such as databases or files, into Kafka topics.
This allows your data to flow seamlessly into your real-time data pipelines.
Why Use Source Connectors?
Imagine you need to move data from a database into Kafka. You could write custom code, but that takes time and effort.
Source Connectors simplify this process by:
- Reducing boilerplate code: No need to write custom producers.
- Providing fault tolerance: They handle failures and resume data transfer.
- Scaling easily: Distribute work across multiple Kafka Connect workers.
- Offering pre-built solutions: Many common connectors are already available.
How Source Connectors Work
At a high level, a source connector operates by:
- Polling Data: It continuously checks the external system for new or updated data.
- Converting Data: It transforms the external data format into Kafka records.
- Producing to Kafka: These records are then sent to a specified Kafka topic.
The Kafka Connect framework manages the connector's lifecycle and distributes its tasks.
Common Source Connector Types
Kafka Connect has a rich ecosystem of connectors. Here are a few popular examples:
- FileStreamSourceConnector: Reads data from local files. Great for initial testing!
- JdbcSourceConnector: Connects to relational databases (like PostgreSQL, MySQL) to pull data.
- S3 Source Connector: Ingests data from Amazon S3 buckets.
- Cloud-specific connectors: For Google Cloud Storage, Azure Blob Storage, etc.
Each connector is designed for a specific data source.
Essential Connector Configuration
When you set up a connector, you provide a configuration. This is typically a JSON or properties file.
Key properties include:
name: A unique name for your connector instance.connector.class: The fully qualified class name of the connector to use (e.g.,FileStreamSourceConnector).tasks.max: The maximum number of tasks the connector can use to parallelize data ingestion.
Other properties are specific to the connector's type.
Example: FileStreamSource Connector
Let's use the FileStreamSourceConnector for a practical example. It's simple and helps demonstrate the core concepts.
This connector reads new lines appended to a specified file and publishes each line as a message to a Kafka topic.
First, let's create a simple input file named test.txt with some initial content.
Configuring Our FileStreamSource
To tell the FileStreamSourceConnector what to do, we create a configuration file. Let's call it file-source-connector.json:
{
"name": "local-file-source",
"config": {
"connector.class": "org.apache.kafka.connect.file.FileStreamSourceConnector",
"tasks.max": "1",
"file": "/path/to/your/test.txt",
"topic": "file-input-topic"
}
}Remember to replace /path/to/your/test.txt with the actual path to your file.
Deploying the Connector via REST
Kafka Connect clusters expose a REST API to manage connectors. We can use curl to deploy our connector.
Assuming your Kafka Connect worker is running on localhost:8083, you'd send a POST request:
curl -X POST -H "Content-Type: application/json" \
--data @file-source-connector.json \
http://localhost:8083/connectorsThis command tells Kafka Connect to create a new connector using the configuration in our JSON file.
Checking Connector Status
After deploying, you'll want to ensure your connector started correctly. You can check its status using another REST API call:
curl http://localhost:8083/connectors/local-file-source/statusLook for the "state": "RUNNING" in the response. If it's FAILED, check the Kafka Connect worker logs for error details.
Once running, any new lines added to test.txt will appear in the file-input-topic in Kafka!
Quick Check: Source Connector Role
What is the primary function of a Kafka Connect Source Connector?
Recap: Ingesting Data with Connectors
Congratulations! You've learned the essentials of Kafka Connect Source Connectors.
- Source Connectors ingest data from external systems into Kafka.
- They offer a code-free, fault-tolerant, and scalable way to integrate data.
- You configure them with properties like
connector.class,name, andtasks.max. - Deployment and monitoring are done via the Kafka Connect REST API.
Next, we'll explore the other side of the coin: Sink Connectors, for exporting data from Kafka!
คำถามที่พบบ่อย
บทเรียน “ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Apache Kafka & Stream Processing Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Apache Kafka & Stream Processing Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า”
เรียนรู้การกำหนดค่าและนำตัวเชื่อมต่อแหล่งข้อมูลไปใช้งาน เพื่อนำเข้าข้อมูลจากฐานข้อมูล ไฟล์ และแหล่งข้อมูลอื่นเข้าสู่ Kafka คุณปฏิบัติ Apache Kafka & Stream Processing Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Apache Kafka & Stream Processing Fundamentals หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Apache Kafka & Stream Processing Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Apache Kafka & Stream Processing Fundamentals นี้ได้ไหม
ได้ บทเรียน Apache Kafka & Stream Processing Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บทนำสู่ Kafka Connect
- ตัวเชื่อมต่อแหล่งข้อมูลสำหรับการนำเข้า
- ตัวเชื่อมต่อปลายทางสำหรับการส่งออก
- การแปลงข้อความเดี่ยว (SMTs)