0

我有我在 mongo db 中加载的示例 Json 文件,以使用 debezium 连接器发送到 Kafka 连接。我的问题是,尽管原始 json 输入文件中有有效数据,但如何将 RowKey 和 id 键列值转换为 0( Zeros )?以下是产生此错误的步骤。

第 1 步:创建示例 json 文件

{"id":1,"first_name":"Devinne","last_name":"Stubbe","email":"dstubbe0@java.com","gender":"Female","club_status":"platinum","comments":"Extended interactive initiative"}
                    {"id":2,"first_name":"Loise","last_name":"Salt","email":"lsalt1@apple.com","gender":"Female","club_status":"silver","comments":"Optimized neutral standardization"}
                    {"id":3,"first_name":"Benjamen","last_name":"Spittle","email":"bspittle2@howstuffworks.com","gender":"Male","club_status":"platinum","comments":"De-engineered systemic customer loyalty"}
                    {"id":4,"first_name":"Helena","last_name":"Pogosian","email":"hpogosian3@pagesperso-orange.fr","gender":"Female","club_status":"gold","comments":"Phased hybrid definition"}
                    {"id":5,"first_name":"Miller","last_name":"Karolewski","email":"mkarolewski4@g.co","gender":"Male","club_status":"platinum","comments":"Monitored systematic software"}

在customerprofile集合中将此数据加载到mongodb中

rs0:PRIMARY> db.collection.find();
        rs0:PRIMARY> db.customerprofile.find();
        { "_id" : ObjectId("5b6213ba78aae5dc09ef8b5b"), "id" : 1, "first_name" : 
        "Devinne", "last_name" : "Stubbe", "email" : "dstubbe0@java.com", "gender" : 
       "Female", "club_st
       atus" : "platinum", "comments" : "Extended interactive initiative" }
       { "_id" : ObjectId("5b6213ba78aae5dc09ef8b5c"), "id" : 2, "first_name" : 
       "Loise", "last_name" : "Salt", "email" : "lsalt1@apple.com", "gender" : 
       "Female", "club_status"
        : "silver", "comments" : "Optimized neutral standardization" }
        { "_id" : ObjectId("5b6213ba78aae5dc09ef8b5d"), "id" : 3, "first_name" : 
        "Benjamen", "last_name" : "Spittle", "email" : "bspittle2@howstuffworks.com", 
        "gender" : "Male"
        , "club_status" : "platinum", "comments" : "De-engineered systemic customer 
        loyalty" }
        { "_id" : ObjectId("5b6213ba78aae5dc09ef8b5e"), "id" : 4, "first_name" : 
        "Helena", "last_name" : "Pogosian", "email" : "hpogosian3@pagesperso- 
       orange.fr", "gender" : "Fe
       male", "club_status" : "gold", "comments" : "Phased hybrid definition" }
       { "_id" : ObjectId("5b6213ba78aae5dc09ef8b5f"), "id" : 5, "first_name" : 
        "Miller", "last_name" : "Karolewski", "email" : "mkarolewski4@g.co", "gender"    
      : "Male", "club_status" : "platinum", "comments" : "Monitored systematic 
       software" }
       { "_id" : ObjectId("5b6213ba78aae5dc09ef8b60"), "id" : 6, "first_name" : 
       "Cammy", "last_name" : "Suche", "email" : "csuche5@cbsnews.com", "gender" : 
       "Male", "club_status" : "gold", "comments" : "Inverse client-server alliance" 
        }

第2步:创建mongodb debezium连接器配置并在kafka connect中激活连接器

{
  "name": "mongodb-jsondb-connector",
  "config":{
   "connector.class": "io.debezium.connector.mongodb.MongoDbConnector",
   "mongodb.hosts": "rs0/169.254.57.118:27017",
   "mongodb.name": "jsondb",
   "mongodb.members.auto.discover": "false",
   "database.whitelist": "jsondb",
    "transforms": "unwrap",
   "transforms.unwrap.type": 
 "io.debezium.connector.mongodb.transforms.UnwrapFromMongoDbEnvelope",
    "database.history.kafka.topic": "schema-changes.jsondb",
    "key.converter": "org.apache.kafka.connect.json.JsonConverter",
   "key.converter.schemas.enable": "false",
   "value.converter": "org.apache.kafka.connect.json.JsonConverter",
   "value.converter.schemas.enable": "false"
 }
}

第三步:检查主题队列

  ksql> print 'jsondb.jsondb.customerprofile' from beginning;
   Format:JSON
   {"ROWTIME":1533154567091,"ROWKEY":" 

正如您在下面的输出 debezium 中看到的那样,由带有 objectid 的 id 列转换

 \"id\":\"5b6213ba78aae5dc09ef8b5b\"}","id":"5b6213ba78aae5dc09ef8b5b".  

****我的问题是因为我们使用 JsonConvetor 作为密钥转换器,我的 id 列如何用序列号密钥更新?****

 {\"id\":\"5b6213ba78aae5dc09ef8b5b\"}","id":"5b6213ba78aae5dc09ef8b5b","first_name":"Devinne","last_name":"Stubbe","email":"dstubbe0@java.com","gender":"Female","club_status":"platinum","comments":"Extended interactive initiative"}
    {"ROWTIME":1533154567096,"ROWKEY":" 

  {\"id\":\"5b6213ba78aae5dc09ef8b5c\"}","id":"5b6213ba78aae5dc09ef8b5c","first_name":"Loise","last_name":"Salt","email":"lsalt1@apple.com","gender":"Female","club_status":"silver","comments":"Optimized neutral standardization"}
    {"ROWTIME":1533154567096,"ROWKEY":" 

 {\"id\":\"5b6213ba78aae5dc09ef8b5d\"}","id":"5b6213ba78aae5dc09ef8b5d","first_name":"Benjamen","last_name":"Spittle","email":"bspittle2@howstuffworks.com","gender":"Male","club_status":"platinum","comments":"De-engineered systemic customer loyalty"}
{"ROWTIME":1533154567097,"ROWKEY":"{\"id\":\"5b6213ba78aae5dc09ef8b5e\"}","id":"5b6213ba78aae5dc09ef8b5e","first_name":"Helena","last_name":"Pogosian","email":"hpogosian3@pagesperso-orange.fr","gender":"Female","club_status":"gold","comments":"Phased hybrid definition"}
{"ROWTIME":1533154567097,"ROWKEY":"{\"id\":\"5b6213ba78aae5dc09ef8b5f\"}","id":"5b6213ba78aae5dc09ef8b5f","first_name":"Miller","last_name":"Karolewski","email":"mkarolewski4@g.co","gender":"Male","club_status":"platinum","comments":"Monitored systematic software"}
{"ROWTIME":1533154567099,"ROWKEY":"{\"id\":\"5b6213ba78aae5dc09ef8b60\"}","id":"5b6213ba78aae5dc09ef8b60","first_name":"Cammy","last_name":"Suche","email":"csuche5@cbsnews.com","gender":"Male","club_status":"gold","comments":"Inverse client-server alliance"}

第 4 步:从主题队列创建一个流

   CREATE STREAM customers_profile \
    (id integer, first_name string, last_name string, \
     email string, gender string, club_status string, \
    comments string) WITH \ 
    (KAFKA_TOPIC='jsondb.jsondb.customerprofile',VALUE_FORMAT='json'); 

第 5 步:这是流从 CUSTOMER_REPART 接收零(0)的地方

ksql> CREATE STREAM customers_stream WITH 
 (KAFKA_TOPIC='CUSTOMERS_REPART',VALUE_FORMAT='json',PARTITIONS=1) as SELECT * 
 FROM customers_profile PARTITION BY id;   

第 6 步:请检查此打印命令的输出,它在 ROWKEY 和 id 键列值中显示零。他们是从哪里来的?我需要做些什么来确保 ROWKEY 和 id 键列显示原始 json 文件值中的正确值,这些值最初加载到 mongodb 中?

ksql> SET 'auto.offset.reset' = 'earliest';
        Successfully changed local property 'auto.offset.reset' from 'null' to 
        'earliest'
        ksql> print 'CUSTOMERS_REPART' from beginning;
        Format:JSON

"Male","COMMENTS":"反向客户端-服务器联盟","ID":0,"LAST_NAME":"Suche","EMAIL":"csuche5@cbsnews.c {"ROWTIME":1533154567104,"ROWKEY" :"0","CLUB_STATUS":"platinum","GENDER":"Male","COMMENTS":"分阶段统一软件","ID":0,"LAST_NAME":"Suttling","EMAIL":" msuttling7@百度。{"ROWTIME":1533154567104,"ROWKEY":"0","CLUB_STATUS":"gold","GENDER":"Female","COMMENTS":"注重质量的全球软件","ID":0," LAST_NAME":"Stepney","EMAIL":"estepney8@we 阶段统一软件","ID":0,"LAST_NAME":"Suttling","EMAIL":"msuttling7@baidu. {"ROWTIME":1533154567104,"ROWKEY":"0","CLUB_STATUS":"gold","GENDER":"Female","COMMENTS":"注重质量的全球软件","ID":0," LAST_NAME":"Stepney","EMAIL":"estepney8@we 阶段统一软件","ID":0,"LAST_NAME":"Suttling","EMAIL":"msuttling7@baidu. {"ROWTIME":1533154567104,"ROWKEY":"0","CLUB_STATUS":"gold","GENDER":"Female","COMMENTS":"注重质量的全球软件","ID":0," LAST_NAME":"Stepney","EMAIL":"estepney8@we

4

1 回答 1

0

关于你的第一个问题,我认为你看到了https://github.com/debezium/debezium/blob/master/debezium-connector-mongodb/src/main/java/io/debezium/connector/mongodb/transforms的效果/UnwrapFromMongoDbEnvelope.java#L163

关于你的第二个问题,我认为问题在于id integerids 现在包含字符串。

于 2018-08-13T07:37:02.833 回答