Kafka Connect in Action: JDBC Sink

Robin Moffatt · 43K views · 2020 · 37:14

Open on YouTube

Distributed systemsDatabases & storagetutorial

Why Stack Overflow recommends it

Stack Overflow users link it when a JDBC Sink connector fails because the data has no schema, or when they need a worked example of wiring Kafka to a relational database.

Recommended by 1 people across 2 different months, 2020 to 2024.

What it is

A 37-minute hands-on walkthrough by Robin Moffatt of configuring Kafka Connect's JDBC Sink to stream Kafka topics into a database such as MySQL. It covers installing the JDBC driver, debugging errors, insert vs upsert, schema evolution, handling JSON and CSV data, and using ksqlDB to apply a schema to schema-less JSON.

What people said

Recommends Robin Moffatt · 2021-01 · Stack Overflow · on “Proper way to resend messages to topic”

I load messages from kafka topic to database Maybe there is more standart way to handle such situations Yes - it's called Kafka Connect :-) The standard pattern is to do any processing on your data and write it [back to] Kafka topics. Then you use the Kafka topic as a source for a Kafka Connect sink connector, in this case the Kafka Connect JDBC Sink connector [LINK] . Kafka Connect is part of Apache Kafka, and handles restarts, scaleout, failures, etc etc. See also Kafka Connect in Action: JDBC Sink [this video]

Recommends Robin Moffatt · 2021-07 · Stack Overflow · on “Kafka Connect without schema, only JSON”

I want to use JDBC sink connector with JSON and without schema You cannot do this - the JDBC Sink connector streams to a relational database, and relational databases have schemas :-D The JDBC Sink connector therefore requires a schema to be present for the data. Depending on where your data is coming from you have different options. If it's ingested from Kafka Connect, use a converter that supports schemas (Avro, Protobuf, JSON Schema) If it's produced by an application that you have control over, get that application to serialise that data with a schema (Avro, Protobuf, JSON Schema) If it's coming from somewhere you don't have control over then you'll need to pre-process the topic to add a

Cites Robin Moffatt · 2020-04 · Stack Overflow · on “Forwarding messages from Kafka to Elasticsearch and Postgresql”

Your error is here: DataException: JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields. If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration. Since this is the JDBC Sink you must provide a schema to your data. If you have the option, I would suggest you use Avro. If not, you must structure your JSON data as required by Kafka Connect. More info: [this video]

Cites Robin Moffatt · 2020-04 · Stack Overflow · on “Can I define schema on kafka topic?”

If you have a source topic with JSON data that has no schema declared, you must add that schema before you can use the JDBC Sink. Options include: ksqlDB, as shown here: [this video] Kafka Connect's Single Message Transform capabilities. No SMT ships with Apache Kafka that does this but there are prototypes out there [LINK] that could do this. Other stream processing e.g. Kafka Streams Edit : I mean can I define two different jdbc sink to different oracle tables from one kafka topic Yes, each topic can be consumed by multiple sinks. The table.name.format [LINK] configuration option can be used to route the topic to different table names as required.

Cites Robin Moffatt · 2020-06 · Stack Overflow · on “When is a Kafka connector preferred over a Spark streaming solution?”

in which situations I should prefer connectors over the Spark streaming solution. "It Depends" :-) Kafka Connect is part of Apache Kafka, and so has tighter integration with Apache Kafka in terms of security, delivery semantics, etc. If you don't want to write any code, Kafka Connect is easier because it's just JSON to configure and run If you're not using Spark already, Kafka Connect is arguably more straightforward to deploy (run the JVM, pass in the configuration) As a framework, Kafka Connect is more transferable since the concepts are the same, you just plugin the appropriate connector for the technology that you want to integrate with each time Kafka Connect handles all the tricky stuf

Cites Ftisiot · 2021-02 · Stack Overflow · on “Kafka with python: How to send topic to postgreSQL?”

If you want to push data to kafka in JSON format I recently wrote a simple example over here [LINK] . You can also find the kafka python docs [LINK] For the Kafka -> PostgreSQL connection, you might want to use Kafka Connect JDBC [LINK] sink. Kafka Connect is a series of pre-built connector that allows you to push or pull (source or sink in kafka connect terms) data from Kafka by just writing a config file, without having to code or re-invent the wheel over and over again. Kafka connect is NOT language dependant, since all you need is to deploy it in your Kafka environment and set correctly the config file. Just pay attention, if you're planning to use Kafka connect to push data to PostgreSQ

Cites Francois · 2022-01 · Stack Overflow · on “kafka connect with mysql sink”

After it took me several days to get the avro schema to respond correctly when calling the consumer, I am now having no luck with the combination of writing the data to a mysql table. Both separately works. So I can receive messages cleanly. I can also create my own stream and write a few test columns with values to mysql. As a template for this I have the video of Robin Moffatt : [this video] taken. But when I try to write the data from the external stream into mysql, I always get a loop with disconnect. Maybe someone can help me out. Short version: [2022-01-04 15:04:29,243] INFO [my_mysql_sink|task-0] Initializing writer using SQL dialect: MySqlDatabaseDialect (io.confluent.connect.jdbc.sink.Jd

Cites Saurabh khandelwal · 2022-06 · Stack Overflow · on “How to handle the messages in Kafka producer if the retries exhausted”

I have used Approach 1 as mentioned in the above post. I have created the Cosmos DB source connector to fetch User data from the cosmos DB and publish it to the Kafka topic "new_user_registered". Cosmos DB source connector configuration: { "name": "cosmosdb-source-connector", "config": { "connector.class": "com.azure.cosmos.kafka.connect.source.CosmosDBSourceConnector", "tasks.max": "1", "key.converter": "org.apache.kafka.connect.storage.StringConverter", "key.converter.schemas.enable": "false", "value.converter": "org.apache.kafka.connect.json.JsonConverter", "value.converter.schemas.enable": "false", "connect.cosmos.task.poll.interval": "1000", "connect.cosmos.connection.endpoint": " [LINK

Cites calderondev · 2024-09 · Stack Overflow · on “Unknown Magic Byte - Kafka Json”

I resumed the project after some time and finally I succeeded in solving my problem. First, I need to configure my Couchbase Source Connector. There were no changes required (wich you can see above). I started to use schema Registry and ksqldb. My messages wich came from Couchbase was a simple json objects as follows. (Schema less json) {"xyz":"This is a value"} Then by using ksqldb I executed the following statements: CREATE STREAM smjson (xyz VARCHAR) WITH (KAFKA_TOPIC='topicstream', VALUE_FORMAT='JSON'); SELECT * FROM smjson EMIT CHANGES; CREATE STREAM SOME_JSON_AS_AVRO WITH (VALUE_FORMAT='AVRO') AS SELECT * FROM smjson; It's necessary add to your ksqldb server the configuration to connec