0
0
Kafkadevops~10 mins

Source connectors in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Source connectors
Start Connector
Connect to Source System
Read Data from Source
Convert Data to Kafka Format
Send Data to Kafka Topic
Repeat Reading Continuously
Stop Connector
The source connector starts, connects to the source system, reads data, converts it, sends it to Kafka, and repeats until stopped.
Execution Sample
Kafka
name=source-connector
connector.class=FileStreamSourceConnector
tasks.max=1
file=/tmp/input.txt
topic=source-topic
This config sets up a source connector that reads from a file and sends data to a Kafka topic.
Process Table
StepActionSource System StateConnector StateKafka Topic State
1Start connectorFile /tmp/input.txt existsConnector initializedTopic empty
2Connect to sourceFile accessibleConnected to fileTopic empty
3Read line 1File has linesRead first lineTopic empty
4Convert dataLine 1 readData convertedTopic empty
5Send to topicLine 1 readData sentTopic has 1 message
6Read line 2File has more linesRead second lineTopic has 1 message
7Convert dataLine 2 readData convertedTopic has 1 message
8Send to topicLine 2 readData sentTopic has 2 messages
9No more linesEnd of fileWaiting for new dataTopic has 2 messages
10Stop connectorFile unchangedConnector stoppedTopic has 2 messages
💡 Connector stops when manually stopped or on error.
Status Tracker
VariableStartAfter Step 3After Step 5After Step 8Final
Connector StateNot startedReading line 1Sent line 1Sent line 2Stopped
Kafka Topic Messages00122
Source File Lines Read01122
Key Moments - 2 Insights
Why does the connector keep running after reading all current lines?
Because source connectors continuously poll the source for new data, as shown in step 9 where it waits for new data after reaching end of file.
What happens if the source file is not accessible at start?
The connector fails to connect and does not proceed, as indicated in step 2 where connection to source is required before reading.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, how many messages are in the Kafka topic after step 5?
A1
B0
C2
DNone
💡 Hint
Check the 'Kafka Topic State' column at step 5 in the execution table.
At which step does the connector read the second line from the source file?
AStep 3
BStep 6
CStep 8
DStep 9
💡 Hint
Look at the 'Action' column for reading lines in the execution table.
If the source file had no lines, what would the connector state be after step 3?
AReading line 1
BConnector stopped
CWaiting for new data
DData sent
💡 Hint
Refer to the connector behavior when no data is available in the execution table and variable tracker.
Concept Snapshot
Source connectors read data from external systems
Convert data to Kafka format
Send data continuously to Kafka topics
Keep running to capture new data
Configured via connector properties
Full Transcript
Source connectors in Kafka start by connecting to an external source system like a file or database. They read data from that source, convert it into Kafka's message format, and send it to a Kafka topic. This process repeats continuously to capture new data as it arrives. The connector runs until it is stopped manually or encounters an error. The example configuration shows a file source connector reading lines from a file and sending them to a Kafka topic. The execution table traces each step: starting, connecting, reading lines, converting, sending, waiting for new data, and stopping. Variables like connector state, messages in the topic, and lines read from the source change step by step. Key points include understanding that connectors keep running to capture new data and that they must connect successfully to the source before reading. The visual quiz tests understanding of message counts, reading steps, and connector states when no data is present.