简体   繁体   English

MongoSinkConnector 期望找到一个不存在的模式主题

[英]MongoSinkConnector expect to find a schema subject that doesn't exist

I'm trying to use the connect MongoDB kafka connector sink (mongodb-kafka-connect-mongodb-1.7.0) to write avro event from kafka to MongoDB.我正在尝试使用连接 MongoDB kafka 连接器接收器 (mongodb-kafka-connect-mongodb-1.7.0) 将 avro 事件从 kafka 写入 MongoDB。

I have a schema registry set up that works with the kafka consumer example or my custom one, they are I both able to deserialize the event and print them.我设置了一个与 kafka 消费者示例或我的自定义示例一起使用的模式注册表,它们都能够反序列化事件并打印它们。

On the other hand when I run the connector I get the following exception:另一方面,当我运行连接器时,出现以下异常:

Subject '<my-avro-schema-name>-value' not found.; error code: 40401

The higher level stack trace message are:更高级别的堆栈跟踪消息是:

  • Caused by: org.apache.kafka.common.errors.SerializationException: Error retrieving Avro value schema version for id 11由以下原因引起:org.apache.kafka.common.errors.SerializationException:检索 id 11 的 Avro 值模式版本时出错

  • Caused by: org.apache.kafka.connect.errors.DataException: Failed to deserialize data for topic client-order-request to Avro:由以下原因引起:org.apache.kafka.connect.errors.DataException:无法将主题客户端订单请求的数据反序列化到 Avro:

And indeed this subject or this id doesn't exist in the schema-registry, actually the highest id I have is 10 and I do have a subject named <my-avro-schema-name>-key .事实上,这个主题或这个 id 不存在于架构注册表中,实际上我拥有的最高 id 是 10,我确实有一个名为<my-avro-schema-name>-key的主题。

Why is the MongoSinkConnector trying find a subject that doesn't exist?为什么 MongoSinkConnector 试图找到一个不存在的主题?

Connect properties:连接属性:

bootstrap.servers=<value>
offset.storage.file.filename=/tmp/connect.offsets
offset.flush.interval.ms=10000
plugin.path=/git/1.libraries/kafka_2.12-2.2.0/plugins

MongoSink properties: MongoSink 属性:

name=<my-avro-schema-name>-sink
connector.class=com.mongodb.kafka.connect.MongoSinkConnector
connection.uri=mongodb://<value>
database=Test
collection=test
topics=test
key.converter=org.apache.kafka.connect.storage.StringConverter

value.converter=io.confluent.connect.avro.AvroConverter
value.converter.schema.registry.url=http://<address>

schema-registry.properties:模式-registry.properties:

listeners=http://0.0.0.0:8081
kafkastore.bootstrap.servers=<address>
kafkastore.topic=_schemas
debug=false
auto.register.schemas=false
use.latest.version=true

Kafka producer configuraton: Kafka生产者配置:

Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "<broker-address>");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
props.put(ProducerConfig.CLIENT_ID_CONFIG, "Kafka Avro  Producer");
props.put("schema.registry.url", "<schema-registry>");

KafkaProducer<String, AllEventsUnion> producerRequest = new KafkaProducer<>(props);

AllEventsUnion clientOrderRequest = createClientOrderRequest();
            
final ProducerRecord<String, AllEventsUnion> producerOrderRequest = new ProducerRecord<>("all-events-union",
                    "ClientOrderRequest-" + calendar.getTimeInMillis(), clientOrderRequest);

The AllEventsUnion is a union avro schema of multiple types. AllEventsUnion 是多种类型的联合 avro 模式。 I'm using it to send different event type to the same kafka topic, which is why I thought I needed to register it before hand.我正在使用它向同一个 kafka 主题发送不同的事件类型,这就是为什么我认为我需要事先注册它。 But apparently you don't need to register schema before using them in the schema registry?但显然您不需要在模式注册表中使用它们之前注册模式?

I do have a subject named <my-avro-schema-name>-key我有一个名为<my-avro-schema-name>-key的主题

This would indicate you have Avro keys.这表明您拥有 Avro 密钥。

Then why use key.converter=org.apache.kafka.connect.storage.StringConverter rather than AvroConverter?那为什么要用key.converter=org.apache.kafka.connect.storage.StringConverter而不是 AvroConverter?

indeed this subject or this id doesn't exist in the schema-registry实际上这个主题或这个 id 在模式注册表中不存在

Then your Avro producer, upstream from the connector (if exists), is having a problem and has not registered the schema/subject or actually written Avro data using the schema registry.然后,连接器上游的 Avro 生产者(如果存在)出现问题,并且没有使用模式注册表注册模式/主题或实际写入 Avro 数据。

Why is the MongoSinkConnector trying find a subject that doesn't exist?为什么 MongoSinkConnector 试图找到一个不存在的主题?

Because you've set this, and the data in the topic contains the ID to some non-existing subject.因为您已经设置了它,并且主题中的数据包含一些不存在的主题的 ID。

value.converter=io.confluent.connect.avro.AvroConverter

Registering a schema after the data is produced will not modify data that's already in the topic you're consuming with other Avro information在生成数据后注册模式不会修改您正在与其他 Avro 信息一起使用的主题中已有的数据

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

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