Complete the code to create a Kafka connector that reads data from an external database.
connector_config = {
"name": "my-connector",
"connector.class": "[1]",
"tasks.max": "1",
"connection.url": "jdbc:mysql://localhost:3306/mydb"
}The io.confluent.connect.jdbc.JdbcSourceConnector class is used to connect Kafka to an external database as a source.
Complete the code to specify the Kafka topic where data from the external system will be sent.
connector_config = {
"name": "my-connector",
"topic": "[1]",
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector"
}The topic property defines the Kafka topic where the connector sends data. Here, external_data is a suitable topic name.
Fix the error in the connector configuration to properly specify the maximum number of tasks.
connector_config = {
"name": "my-connector",
"tasks.max": [1],
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector"
}The tasks.max property must be an integer, so 1 is correct. Using a string or boolean causes errors.
Fill both blanks to create a dictionary comprehension that maps table names to their Kafka topics only if the table name starts with 'user'.
table_topic_map = {table: table[1] for table in tables if table[2]'user')}The comprehension uses .upper() to convert table names to uppercase for topics, and .startswith( to filter tables starting with 'user'.
Fill all three blanks to create a filtered dictionary comprehension that maps uppercase table names to their topics only if the table name length is greater than 4.
filtered_map = {table[1]: table for table in tables if len(table) [2] [3]The comprehension converts table names to uppercase for keys, and filters tables with length greater than 4.