Kafka-Connect JDBC接收器连接器和Avro在第二次插入时失败

时间:2019-09-02 07:47:22

标签: jdbc apache-kafka avro apache-kafka-connect confluent-schema-registry

我正在尝试遵循基于Confluent教程的基本JDBCSinkConnector示例。该示例使用具有Avro主题和架构注册表的MySql数据库。

该示例适用于到达该主题的第一条消息,并将数据正确插入到MySQL表中,但是对于第二条消息,我收到错误消息“找不到ID为26的模式”

  1. 首先创建接收器作业:
{
  "name" :"mySqlTest5",
  "config": {
   "connector.class":"io.confluent.connect.jdbc.JdbcSinkConnector",
    "connection.user":"root",
    "connection.password":"some-password",
    "topics":"orders",
    "tasks.max":1,
       "auto.create":true,
    "connection.url":"jdbc:mysql://some-url",
    "value.converter": "io.confluent.connect.avro.AvroConverter",
    "key.converter": "org.apache.kafka.connect.storage.StringConverter",
    "value.converter.schema.registry.url": "http://dp-cp-schema-registry:8081",
    "insert.mode" :"upsert",
    "pk.mode" : "record_value",
    "pk.fields": "id"
    }
}
  1. 然后将第一个消息发送到主题:
kafka-avro-console-producer --broker-list kafka:9092 \
--topic orders3 \
--property schema.registry.url=http://schema-registry:8081 \                                       
--property value.schema='{"type":"record","name":"orders","fields": \
[{"name":"id","type":"int"},{"name":"product", "type": "string"},
{"name":"quantity", "type": "int"}, {"name":"price",
"type": "float"}]}'

制作人准备好用户输入后,我输入:

{"id": 999, "product": "foo", "quantity": 100, "price": 50}

这会将项目成功插入数据库!

  1. 当控制台生产者仍在等待用户输入时,我输入第二条消息:
{"id": 101, "product": "bar", "quantity": 200, "price": 70}

这会导致以下异常:

  

>   检索ID为26的Avro模式时出错   连接服务器原因:io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException:未找到架构;错误代码:40403   在io.confluent.kafka.schemaregistry.client.rest.RestService.sendHttpRequest(RestService.java:230)   在io.confluent.kafka.schemaregistry.client.rest.RestService.httpRequest(RestService.java:256)   在io.confluent.kafka.schemaregistry.client.rest.RestService.lookUpSubjectVersion(RestService.java:323)   在io.confluent.kafka.schemaregistry.client.rest.RestService.lookUpSubjectVersion(RestService.java:311)   在io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.getVersionFromRegistry(CachedSchemaRegistryClient.java:184)   在io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.getVersion(CachedSchemaRegistryClient.java:297)   在io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer.schemaVersion(AbstractKafkaAvroDeserializer.java:202)   在io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer.deserialize(AbstractKafkaAvroDeserializer.java:158)   在io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer.deserializeWithSchemaAndVersion(AbstractKafkaAvroDeserializer.java:243)   在io.confluent.connect.avro.AvroConverter $ Deserializer.deserialize(AvroConverter.java:134)

我不明白为什么第一条消息会正确插入,并且还会在架构注册表(/ subjects / orders-value)中产生带有正确ID的主题,但第二条插入会失败。

更新: 由于某些原因,Avro消息容器中的架构数据有一个额外的字段(schema.registrey.schema.version = 1) 原始模式不包括此字段,但它出现在日志中:  使用输入{“ schema”:“ {\” type \“:\” record \“,\” name \“:\” statuses \“,\” namespace \“:\” my.namespace \“,\发送POST从“ fields \” […] \“ schema.registry.schema.version \”:1}“}到http://dp-cp-schema-registry:8081/subjects/mySubject?deleted=true(io.confluent.kafka.schemaregistry.client.rest.RestService) 管道中的哪个进程正在添加此“ schema.registry.schema.version”字段?

0 个答案:

没有答案