What if you could stop writing endless code just to get your data flowing into Kafka?
Why Source connectors in Kafka? - Purpose & Use Cases
Imagine you have data scattered across many places like databases, files, or apps, and you want to bring all that data into Kafka to process it. Doing this by hand means writing lots of custom code to connect, read, and send data continuously.
Manually coding each connection is slow and tricky. You might miss updates, lose data, or create bugs. Every time the source changes, you must fix your code. It's like trying to carry water with a leaky bucket--inefficient and frustrating.
Source connectors automate this work. They are ready-made tools that connect to your data sources and stream data into Kafka reliably and continuously. You just configure them once, and they handle the rest, saving time and avoiding errors.
while True: data = read_from_database() send_to_kafka(data) sleep(5)
configure_source_connector({"name": "db-connector", "tasks.max": 1, "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector", "connection.url": "jdbc:mysql://..."})Source connectors let you easily and reliably stream data from many systems into Kafka, unlocking real-time data processing and integration.
A company wants to stream new sales records from their SQL database into Kafka to update dashboards instantly. Using a source connector, they set it up once and get live sales data flowing without writing extra code.
Manually connecting data sources to Kafka is slow and error-prone.
Source connectors automate and simplify streaming data into Kafka.
This enables real-time data integration and faster insights.
Practice
Solution
Step 1: Understand the role of source connectors
Source connectors are designed to bring data from outside systems into Kafka topics automatically.Step 2: Differentiate from sink connectors
Sink connectors do the opposite by exporting data from Kafka to external systems, so they are not the correct answer here.Final Answer:
To automatically import data from external systems into Kafka topics -> Option AQuick Check:
Source connector = import data [OK]
- Confusing source connectors with sink connectors
- Thinking connectors manage Kafka internals like partitions
- Assuming connectors monitor Kafka health
Solution
Step 1: Recall Kafka Connect configuration syntax
The key to specify the connector implementation class is always "connector.class" in the JSON config.Step 2: Eliminate incorrect options
Other options like "source.class", "connectorType", or "sourceConnector" are not valid Kafka Connect configuration keys.Final Answer:
"connector.class" -> Option DQuick Check:
Connector class key = "connector.class" [OK]
- Using incorrect or made-up JSON keys
- Confusing source connector config keys with sink connector keys
- Omitting quotes around JSON keys
{
"name": "my-source-connector",
"connector.class": "FileStreamSource",
"tasks.max": "1",
"file": "/tmp/input.txt",
"topic": "test-topic"
}What will happen when this connector runs?
Solution
Step 1: Identify connector type and purpose
The "FileStreamSource" connector reads data from a file and sends it to a Kafka topic.Step 2: Understand configuration keys
"file" specifies the input file, "topic" specifies the Kafka topic to write to, and "tasks.max" as a string is acceptable in JSON configs.Final Answer:
It reads data from /tmp/input.txt and writes it to the Kafka topic 'test-topic' -> Option BQuick Check:
FileStreamSource reads file to topic [OK]
- Confusing source and sink connectors
- Thinking 'tasks.max' must be integer type (string is valid in JSON)
- Assuming connector creates topics automatically
{
"name": "my-connector",
"connector.class": "JdbcSourceConnector",
"tasks.max": 2,
"connection.url": "jdbc:mysql://localhost:3306/mydb",
"topic.prefix": "db-"
}But the connector fails to start. What is the most likely cause?
Solution
Step 1: Review JdbcSourceConnector required properties
JdbcSourceConnector requires a 'mode' property to specify how to query the database (e.g., 'incrementing', 'timestamp+incrementing').Step 2: Check other properties
'tasks.max' as integer is valid, 'topic.prefix' is correct, and 'connection.url' can be MySQL syntax if using MySQL.Final Answer:
Missing required property 'mode' for JdbcSourceConnector -> Option AQuick Check:
JdbcSourceConnector needs 'mode' property [OK]
- Assuming 'tasks.max' must be string
- Confusing 'topic.prefix' with 'topic.name'
- Thinking connection URL must be PostgreSQL always
Solution
Step 1: Identify connector capabilities
FilePulse source connector supports reading multiple files from a directory and processing CSV files.Step 2: Evaluate other options
FileStreamSource reads only a single file, JdbcSourceConnector is for databases, and manual coding is not using source connectors.Final Answer:
Use a FilePulse source connector configured with the directory path to read all CSV files -> Option CQuick Check:
FilePulse reads multiple files from directory [OK]
- Using FileStreamSource for multiple files
- Trying to use JdbcSourceConnector for CSV files
- Ignoring built-in connectors and coding manually
Ready to prove it?
Pass the test and this pattern moves unknown
