简体   繁体   English

Kafka 使用 JSONConverter 连接 MongoDB Kafka 连接器不起作用

[英]Kafka connect MongoDB Kafka connector using JSONConverter not working

I'm trying to configure the Kafka connector to use mongoDB as the source and send the records into Kakfa topics.我正在尝试将 Kafka 连接器配置为使用 mongoDB 作为源并将记录发送到 Kakfa 主题中。 I've successfully done so, but I'm trying to do it with the JSONConverter in order to also save the schema with the payload.我已经成功地这样做了,但我正在尝试使用 JSONConverter 来做到这一点,以便同时保存带有有效负载的架构。

My problem is that the connector is saving the data as follows:我的问题是连接器正在按如下方式保存数据:

{ "schema": { "type": "string" } , "payload": "{....}" }

In other words, it's automatically assuming the actual JSON is a string and it's saving the schema as String.换句话说,它自动假设实际的 JSON 是一个字符串,并将模式保存为字符串。

This is how I'm setting up the connector:这是我设置连接器的方式:

curl -X POST http://localhost:8083/connectors -H "Content-Type: application/json" -d '{
 "name": "newtopic",
 "config": { 
"tasks.max":1,
 "connector.class":"com.mongodb.kafka.connect.MongoSourceConnector", 
 "key.converter":"org.apache.kafka.connect.json.JsonConverter", 
 "key.converter.schemas.enabled": "true",
 "value.converter":"org.apache.kafka.connect.json.JsonConverter", 
 "value.converter.schemas.enabled": "true",
 "connection.uri":"[MONGOURL]", 
 "database":"dbname", 
 "collection":"collname", 
 "pipeline":"[]", 
 "topic.prefix": "", 
 "publish.full.document.only": "true" 
 }}'

Am I missing something for the configuration?我是否缺少配置的某些内容? Is it simply not able to guess the schema of the document stored in MongoDB, so it goes with String?是不是根本就无法猜测存储在 MongoDB 中的文档的架构,所以它与 String 一起使用?

There's nothing to guess.没什么好猜的。 Mongo is schemaless, last I checked, so the schema is a string or bytes. Mongo 是无模式的,最后我检查过,所以模式是一个字符串或字节。 I would suggest using AvroConverter or setting schema enabled to false我建议使用 AvroConverter 或将 schema enabled 设置为 false

You may also want to try using Debezium to see if you get different results您可能还想尝试使用 Debezium 来查看是否得到不同的结果

The latest version 1.3 of the MongoDB connector should solve this issue. MongoDB 连接器的最新版本 1.3应该可以解决这个问题。
It even provides an option for inferring the source schema.它甚至提供了一个用于推断源模式的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM