Bird
Raised Fist0
Kafkadevops~7 mins

Common connectors (JDBC, S3, Elasticsearch) in Kafka - Commands & Configuration

Choose your learning style10 modes available
Introduction
Kafka connectors help move data between Kafka and other systems like databases, storage, or search engines automatically. They solve the problem of manually writing code to transfer data by providing ready-made tools to connect Kafka with systems like JDBC databases, Amazon S3 storage, and Elasticsearch search engines.
When you want to stream data from a database into Kafka without writing custom code.
When you need to save Kafka topic data as files in Amazon S3 for backup or analytics.
When you want to index Kafka data into Elasticsearch for fast search and analysis.
When you want to keep your data systems synchronized automatically.
When you want to simplify data integration between Kafka and other platforms.
Config File - jdbc-source-connector.properties
jdbc-source-connector.properties
name=jdbc-source-connector
connector.class=io.confluent.connect.jdbc.JdbcSourceConnector
connection.url=jdbc:postgresql://localhost:5432/mydb
connection.user=myuser
connection.password=mypassword
topic.prefix=jdbc-
poll.interval.ms=10000
mode=incrementing
incrementing.column.name=id

This configuration file sets up a Kafka JDBC source connector.

name: unique name for the connector.

connector.class: specifies the JDBC source connector class.

connection.url, connection.user, connection.password: database connection details.

topic.prefix: prefix added to Kafka topics created from database tables.

poll.interval.ms: how often to check the database for new data.

mode and incrementing.column.name: how to detect new rows.

Commands
Starts the Kafka Connect standalone worker with the JDBC source connector configuration to begin streaming data from the database into Kafka topics.
Terminal
connect-standalone /etc/kafka/connect-standalone.properties jdbc-source-connector.properties
Expected OutputExpected
[2024-06-01 12:00:00,000] INFO Kafka Connect started (org.apache.kafka.connect.cli.ConnectStandalone) [2024-06-01 12:00:01,000] INFO Starting connector jdbc-source-connector (org.apache.kafka.connect.runtime.WorkerConnector) [2024-06-01 12:00:02,000] INFO Connector jdbc-source-connector started (org.apache.kafka.connect.runtime.WorkerConnector)
Lists all Kafka topics to verify that topics with the prefix 'jdbc-' have been created by the JDBC source connector.
Terminal
kafka-topics --bootstrap-server localhost:9092 --list
Expected OutputExpected
jdbc-mytable jdbc-anothertable
→
--bootstrap-server - Specifies the Kafka server to connect to.
Starts the Kafka Connect standalone worker with an S3 sink connector configuration to save Kafka topic data into Amazon S3 storage.
Terminal
connect-standalone /etc/kafka/connect-standalone.properties s3-sink-connector.properties
Expected OutputExpected
[2024-06-01 12:05:00,000] INFO Kafka Connect started (org.apache.kafka.connect.cli.ConnectStandalone) [2024-06-01 12:05:01,000] INFO Starting connector s3-sink-connector (org.apache.kafka.connect.runtime.WorkerConnector) [2024-06-01 12:05:02,000] INFO Connector s3-sink-connector started (org.apache.kafka.connect.runtime.WorkerConnector)
Starts the Kafka Connect standalone worker with an Elasticsearch sink connector configuration to index Kafka topic data into Elasticsearch for search and analytics.
Terminal
connect-standalone /etc/kafka/connect-standalone.properties elasticsearch-sink-connector.properties
Expected OutputExpected
[2024-06-01 12:10:00,000] INFO Kafka Connect started (org.apache.kafka.connect.cli.ConnectStandalone) [2024-06-01 12:10:01,000] INFO Starting connector elasticsearch-sink-connector (org.apache.kafka.connect.runtime.WorkerConnector) [2024-06-01 12:10:02,000] INFO Connector elasticsearch-sink-connector started (org.apache.kafka.connect.runtime.WorkerConnector)
Key Concept

If you remember nothing else, remember: Kafka connectors automate moving data between Kafka and other systems without writing custom code.

Common Mistakes
Not setting the correct database connection URL or credentials in the JDBC connector config.
The connector cannot connect to the database, so no data is streamed.
Double-check and test the database URL, username, and password before starting the connector.
Forgetting to start Kafka Connect with the connector configuration file.
Kafka Connect won't load the connector, so no data movement happens.
Always run the connect-standalone or connect-distributed command with the correct connector config file.
Using incorrect topic names or prefixes when verifying topics.
You may think the connector failed when topics exist but under a different name.
Check the topic.prefix setting and list topics carefully.
Summary
Kafka connectors simplify data integration by automating data flow between Kafka and systems like databases, S3, and Elasticsearch.
You configure connectors with properties files specifying connection details and behavior.
You start connectors using Kafka Connect commands and verify topics or data destinations to confirm operation.

Practice

(1/5)
1. What is the main purpose of a JDBC connector in Kafka?
easy
A. To monitor Kafka cluster health
B. To store Kafka data in cloud object storage
C. To enable full-text search on Kafka data
D. To move data between Kafka and relational databases

Solution

  1. Step 1: Understand JDBC connector role

    JDBC connectors are designed to connect Kafka with relational databases using JDBC protocol.
  2. Step 2: Match purpose with options

    To move data between Kafka and relational databases correctly states moving data between Kafka and databases, which is the JDBC connector's main use.
  3. Final Answer:

    To move data between Kafka and relational databases -> Option D
  4. Quick Check:

    JDBC connector = database integration [OK]
Hint: JDBC always relates to databases and Kafka [OK]
Common Mistakes:
  • Confusing JDBC with S3 or Elasticsearch connectors
  • Thinking JDBC stores data in cloud storage
  • Assuming JDBC is for search functionality
2. Which of the following is the correct configuration property to specify the S3 bucket name in a Kafka S3 sink connector?
easy
A. s3.bucket.name
B. bucket.name.s3
C. s3.bucket
D. bucket.s3.name

Solution

  1. Step 1: Recall S3 connector config syntax

    The standard property to specify the bucket is s3.bucket.name.
  2. Step 2: Compare options with standard property

    Only s3.bucket.name matches the correct property name exactly.
  3. Final Answer:

    s3.bucket.name -> Option A
  4. Quick Check:

    Bucket name property = s3.bucket.name [OK]
Hint: S3 config keys start with 's3.' prefix [OK]
Common Mistakes:
  • Swapping order of words in property name
  • Using incorrect prefixes like 'bucket.s3'
  • Missing the '.name' suffix
3. Given the following Kafka Elasticsearch sink connector config snippet:
{
  "connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
  "topics": "orders",
  "connection.url": "http://localhost:9200",
  "type.name": "_doc",
  "key.ignore": "false"
}

What will happen when a message with key 'order123' and value '{"item":"book"}' is sent to topic 'orders'?
medium
A. The message will be stored in Kafka only, not sent to Elasticsearch
B. The document will be indexed with a random ID ignoring the key
C. The document will be indexed in Elasticsearch with ID 'order123'
D. The connector will fail due to missing authentication

Solution

  1. Step 1: Analyze key.ignore setting

    Since "key.ignore" is set to "false", the connector uses the Kafka message key as the Elasticsearch document ID.
  2. Step 2: Understand indexing behavior

    The message with key 'order123' will be indexed in Elasticsearch with that key as the document ID.
  3. Final Answer:

    The document will be indexed in Elasticsearch with ID 'order123' -> Option C
  4. Quick Check:

    key.ignore=false means use key as ID [OK]
Hint: key.ignore=false means use Kafka key as ES document ID [OK]
Common Mistakes:
  • Assuming key is ignored by default
  • Thinking connector fails without auth (not always true)
  • Confusing Kafka storage with Elasticsearch indexing
4. You configured a Kafka JDBC source connector but it is not importing any data. Which of the following is the most likely cause?
medium
A. The Kafka topic name is missing in the connector config
B. The JDBC URL is incorrect or unreachable
C. The connector class is set to ElasticsearchSinkConnector
D. The S3 bucket name is not specified

Solution

  1. Step 1: Check connectivity issues

    If the JDBC URL is wrong or unreachable, the connector cannot read data from the database.
  2. Step 2: Evaluate other options

    The Kafka topic name is missing in the connector config would cause errors but usually the connector won't start; The connector class is set to ElasticsearchSinkConnector is wrong connector type; The S3 bucket name is not specified is unrelated to JDBC source.
  3. Final Answer:

    The JDBC URL is incorrect or unreachable -> Option B
  4. Quick Check:

    Bad JDBC URL = no data import [OK]
Hint: Always verify JDBC URL connectivity first [OK]
Common Mistakes:
  • Confusing connector class for source vs sink
  • Ignoring missing topic config errors
  • Checking unrelated S3 settings for JDBC issues
5. You want to archive Kafka topic data to S3 daily and also enable fast search on the same data using Elasticsearch. Which connector setup is the best approach?
hard
A. Use an S3 sink connector for archiving and an Elasticsearch sink connector for search, both consuming from the same Kafka topic
B. Use only an S3 sink connector and query S3 directly for search
C. Use a JDBC sink connector to store data in a database, then export to S3 and Elasticsearch from there
D. Use an Elasticsearch source connector to send data to S3

Solution

  1. Step 1: Understand connector roles

    S3 sink connector archives data to cloud storage; Elasticsearch sink connector indexes data for search.
  2. Step 2: Choose correct architecture

    Using both sink connectors on the same Kafka topic allows parallel archiving and search capabilities efficiently.
  3. Final Answer:

    Use an S3 sink connector for archiving and an Elasticsearch sink connector for search, both consuming from the same Kafka topic -> Option A
  4. Quick Check:

    Separate sinks for archive and search = best practice [OK]
Hint: Use separate sink connectors for storage and search [OK]
Common Mistakes:
  • Trying to search data directly in S3 without indexing
  • Using JDBC sink unnecessarily for this use case
  • Confusing source and sink connector roles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard