[英]In Kafka, the "Key" does not match the "Id" when updating the document in MongoDB
We are trying to take all the records from MongoDB to Kafka using the com.mongodb.kafka.connect.MongoSourceConnector.我们正在尝试使用 com.mongodb.kafka.connect.MongoSourceConnector 将 MongoDB 的所有记录带到 Kafka。 The settings are used for connector as follows:
用于连接器的设置如下:
{
"name": "mongo-source",
"config": {
"connector.class": "com.mongodb.kafka.connect.MongoSourceConnector",
"connection.uri": "mongodb:***:27017/?authSource=admin&replicaSet=myMongoCluster&authMechanism=SCRAM-SHA-256",
"database": "someDb",
"collection": "someCollection",
"output.format.value":"json",
"output.format.key":"json",
"key.converter.schemas.enable":"false",
"value.converter.schemas.enable":"false",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"value.converter":"org.apache.kafka.connect.storage.StringConverter",
"publish.full.document.only": "true",
"change.stream.full.document":"updateLookup",
"copy.existing": "true"
}
}
When all documents are initially uploaded from MongoDB to Kafka, the "key" corresponds to the "id" from Mongo document:当所有文档最初从 MongoDB 上传到 Kafka 时,“key”对应于 Mongo 文档中的“id”:
{"_id": {"_id": {"$oid": "5e54fd0fbb5b5a7d35737232"}, "copyingData": true}}
But when a document in MongoDB is updated, an update with a different "key" gets into Kafka:但是当 MongoDB 中的文档更新时,带有不同“密钥”的更新会进入 Kafka:
{"_id": {"_data": "82627B2EF6000000022B022C0100296E5A1004A47945EC361D42A083988C14D982069C46645F696400645F0FED2B3A35686E505F5ECA0004"}}
Thus, the consumer cannot identify the initially uploaded document and update for it.因此,消费者无法识别最初上传的文档并对其进行更新。
Please help me find which settings on the Kafka, Connector or MongoDB side are responsible for this and how I can change the "Key" in Kafka to the same as during the initial upload.请帮我找出 Kafka、Connector 或 MongoDB 端的哪些设置对此负责,以及如何将 Kafka 中的“密钥”更改为与初始上传期间相同。
We were facing the same issue and after some search we started using the following config.我们面临同样的问题,经过一番搜索,我们开始使用以下配置。 We defined a avro schema to extract the output schema key.
我们定义了一个 avro 模式来提取 output 模式键。 The key is generated consistently and looks like
密钥是一致生成的,看起来像
Struct{fullDocument._id=e2ce4bfe-d03a-4192-830d-895df5a4b095}
结构{fullDocument._id=e2ce4bfe-d03a-4192-830d-895df5a4b095}
Here "e2ce4bfe-d03a-4192-830d-895df5a4b095" is the document id.这里“e2ce4bfe-d03a-4192-830d-895df5a4b095”是文档ID。
{
"change.stream.full.document" : "updateLookup",
"connection.uri" : "<connection_uri>",
"connector.class" : "com.mongodb.kafka.connect.MongoSourceConnector",
"collection": "someCollection",
"copy.existing" : "true",
"database" : "someDb",
"key.converter" : "org.apache.kafka.connect.storage.StringConverter",
"key.converter.schemas.enable" : "false",
"key.serializer" : "org.apache.kafka.connect.storage.StringConverter",
"name" : "mongo-source",
"output.format.key" : "schema",
"output.json.formatter" : "com.mongodb.kafka.connect.source.json.formatter.SimplifiedJson"
"publish.full.document.only" : "true",
"output.schema.key": "{\"type\":\"record\",\"name\":\"keySchema\",\"fields\":[{\"name\":\"fullDocument._id\",\"type\":\"string\"}]}",
"tasks.max" : "1",
"value.converter" : "org.apache.kafka.connect.storage.StringConverter",
"value.converter.schemas.enable" : "false"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.