📖 Scenario: You are working on a data pipeline that collects data from a database and sends it to Kafka topics for processing.
🎯 Goal: Set up a Kafka source connector configuration to pull data from a MySQL database into Kafka.
📋 What You'll Learn
Create a JSON configuration for a Kafka source connector
Specify the connector class for MySQL
Set the connection URL, user, and password
Define the Kafka topic prefix
Print the final JSON configuration
💡 Why This Matters
🌍 Real World
Kafka source connectors are used to automatically pull data from databases or other systems into Kafka topics for real-time processing.
💼 Career
Understanding how to configure Kafka connectors is important for data engineers and developers working with streaming data pipelines.
Progress0 / 4 steps
1
Create the base JSON configuration
Create a variable called connector_config and assign it a dictionary with the key "name" set to "mysql-source-connector".
Kafka
Hint
Use a dictionary with the key 'name' and value 'mysql-source-connector'.
2
Add connector class and database connection details
Add to connector_config a key "config" with a nested dictionary containing these exact entries: "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector", "connection.url": "jdbc:mysql://localhost:3306/mydb", "connection.user": "user", and "connection.password": "password".
Kafka
Hint
Add a 'config' key with a nested dictionary containing the connector class and connection details.
3
Add topic prefix and table whitelist
Inside connector_config["config"], add the keys "topic.prefix" with value "mysql-" and "table.whitelist" with value "customers".
Kafka
Hint
Add 'topic.prefix' and 'table.whitelist' keys inside the 'config' dictionary.
4
Print the connector configuration JSON
Import the json module and print the JSON string of connector_config using json.dumps() with indentation of 2.
Kafka
Hint
Use json.dumps(connector_config, indent=2) inside print to display the JSON nicely.
Practice
(1/5)
1. What is the main purpose of a Kafka source connector?
easy
A. To automatically import data from external systems into Kafka topics
B. To export data from Kafka topics to external systems
C. To monitor Kafka cluster health
D. To manage Kafka topic partitions
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 A
Quick Check:
Source connector = import data [OK]
Hint: Source connectors bring data into Kafka topics [OK]
Common Mistakes:
Confusing source connectors with sink connectors
Thinking connectors manage Kafka internals like partitions
Assuming connectors monitor Kafka health
2. Which of the following is the correct JSON field to specify the connector class in a Kafka source connector configuration?
easy
A. "sourceConnector"
B. "source.class"
C. "connectorType"
D. "connector.class"
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 D
Quick Check:
Connector class key = "connector.class" [OK]
Hint: Use "connector.class" to specify connector type [OK]
Common Mistakes:
Using incorrect or made-up JSON keys
Confusing source connector config keys with sink connector keys
Omitting quotes around JSON keys
3. Given this Kafka Connect source connector configuration snippet: