Sink connectors in Kafka - Commands & Configuration
{
"name": "example-sink-connector",
"config": {
"connector.class": "FileStreamSinkConnector",
"tasks.max": "1",
"topics": "example-topic",
"file": "/tmp/output.txt",
"key.converter": "org.apache.kafka.connect.storage.StringConverter",
"value.converter": "org.apache.kafka.connect.storage.StringConverter"
}
}This JSON configures a sink connector named example-sink-connector.
connector.class specifies the type of sink connector; here it writes to a file.
tasks.max sets how many parallel tasks run.
topics lists Kafka topics to read from.
file is the output file path where data will be saved.
key.converter and value.converter define how Kafka data is converted to strings.
curl -X POST -H "Content-Type: application/json" --data @sink-connector.json http://localhost:8083/connectors
-X POST - Specifies the HTTP method to create the connector.-H "Content-Type: application/json" - Sets the content type to JSON for the request.--data @sink-connector.json - Sends the connector configuration file as the request body.curl http://localhost:8083/connectors/example-sink-connector/status
tail -f /tmp/output.txt-f - Follows the file to show new data as it arrives.Sink connectors automatically export Kafka topic data to external systems without manual coding.
Practice
What is the main purpose of a Kafka sink connector?
Solution
Step 1: Understand the role of sink connectors
Sink connectors are designed to export data from Kafka topics to other systems.Step 2: Differentiate from source connectors
Source connectors import data into Kafka, while sink connectors export data out.Final Answer:
To move data from Kafka topics to external systems automatically -> Option DQuick Check:
Sink connector = export data from Kafka [OK]
- Confusing sink with source connectors
- Thinking sink connectors create topics
- Assuming sink connectors monitor Kafka health
Which of the following is a correct JSON field to specify the Kafka topic for a sink connector configuration?
{
"name": "my-sink-connector",
"config": {
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
"topics": "my_topic",
"connection.url": "jdbc:mysql://localhost:3306/mydb"
}
}Solution
Step 1: Check the standard Kafka Connect config field
The field to specify Kafka topics in sink connector config is "topics" (plural).Step 2: Verify the example JSON
The example uses "topics": "my_topic", which is correct syntax.Final Answer:
"topics" -> Option AQuick Check:
Kafka sink config uses "topics" field [OK]
- Using "topic" (singular) instead of "topics"
- Using non-standard fields like "topic_name"
- Confusing source connector fields with sink
Given this sink connector config snippet, what will be the destination system?
{
"name": "file-sink-connector",
"config": {
"connector.class": "FileStreamSink",
"topics": "logs",
"file": "/tmp/output.log"
}
}Solution
Step 1: Identify the connector class
The connector class is "FileStreamSink", which writes data to a file.Step 2: Check the "file" config field
The "file" field specifies the destination file path "/tmp/output.log".Final Answer:
A file located at /tmp/output.log -> Option BQuick Check:
FileStreamSink writes to file path [OK]
- Assuming data goes back to Kafka topic
- Confusing sink with source connectors
- Thinking it writes to a database or HTTP
Identify the error in this sink connector config JSON:
{
"name": "jdbc-sink",
"config": {
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
"topic": "orders",
"connection.url": "jdbc:postgresql://localhost:5432/shop"
}
}Solution
Step 1: Check the topic field name
The config uses "topic" (singular), but Kafka sink connectors require "topics" (plural).Step 2: Verify other fields
The JDBC URL and connector class are correctly formatted, and "name" is present.Final Answer:
Missing 'topics' field; uses 'topic' instead -> Option CQuick Check:
Use "topics" not "topic" in sink config [OK]
- Using singular "topic" instead of "topics"
- Assuming JDBC URL is wrong without checking
- Thinking connector class name is invalid
You want to export data from multiple Kafka topics to a single database table using a JDBC sink connector. Which configuration approach is correct?
{
"name": "multi-topic-jdbc-sink",
"config": {
"connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
"topics": "topic1,topic2,topic3",
"connection.url": "jdbc:mysql://localhost:3306/mydb",
"table.name.format": "combined_table"
}
}Solution
Step 1: Understand 'topics' field with multiple topics
The "topics" field lists multiple topics separated by commas, which is valid.Step 2: Check 'table.name.format' usage
Setting "table.name.format" to a fixed table name causes all data to go into that single table.Step 3: Confirm connector behavior
The JDBC sink connector supports writing multiple topics to one table if configured this way.Final Answer:
This config exports all topics to one table named 'combined_table' -> Option AQuick Check:
Multiple topics + fixed table name = single table export [OK]
- Assuming multiple topics create separate tables automatically
- Thinking multiple topics are not allowed in sink config
- Ignoring 'table.name.format' effect
Ready to prove it?
Pass the test and this pattern moves unknown
