【问题标题】:confluent kafka producer avro schema error ClientError: Schema parse failed: Unknown named schemaconfluent kafka producer avro schema error ClientError: Schema parse failed: Unknown named schema
【发布时间】:2021-11-17 04:55:01
【问题描述】:

我在 kafka 的生产者方面工作,以在主题中推送消息。 我正在使用confluent-kafkaavro producer。

Liked issue on github

以下是我的架构.avsc 文件。

Keys.avsc

{
    "namespace": "io.codebrews.schema.test",
    "type": "record",
    "name": "Keys",
    "fields": [
        {
            "name": "name",
            "type": "string"
        },
        {
            "name": "email",
            "type": "string"
        }
    ]
}

Test.avsc

{
    "namespace": "io.codebrews.schema.test",
    "type": "record",
    "name": "Subscription",
    "fields": [
        {
            "name": "test",
            "type": "string"
        },
        {
            "name": "keys",
            "type": "io.codebrews.schema.test.Keys"
        }
    ]
}

Producer.py

key_schema, value_schema = load_avro_schema_from_file('Subscription.avsc')

try:
    producer = avro.AvroProducer(producer_config, default_key_schema=key_schema, default_value_schema=value_schema)
except Exception as e:
    raise e

def load_avro_schema_from_file(schema_file):
    key_schema_string = """
    {"type": "string"}
    """

    key_schema = avro.loads(key_schema_string)
    value_schema = avro.load("./avro/" + schema_file)

    return key_schema, value_schema

当我尝试注册Keys.avsc 时,它工作正常,没有错误。但是当我在注册Keys.avsc 后尝试注册Test.avsc 时。我得到以下错误。

confluent_kafka.avro.error.ClientError:架构解析失败:未知命名架构“io.codebrews.schema.test.Keys”,已知名称:['io.codebrews.schema.test.Subscription']。

手动注册架构后。

{
    "namespace": "io.codebrews.schema.test",
    "type": "record",
    "name": "Subscription",
    "fields": [
        {
            "name": "test",
            "type": "string"
        },
        {
            "name": "keys",
            "type": "Keys"
        }
    ]
}

在我的主题中推送消息时,出现以下错误。

ClientError: Incompatible Avro schema:409 message:{'error_code': 409, 'message': '正在注册的模式与主题“test-value”的早期模式不兼容。

我在这里做错了吗?

还有谁能帮我如何在 python 中停止自动模式注册?

【问题讨论】:

    标签: python avro confluent-kafka-python


    【解决方案1】:

    错误与解析器有关,与注册表注册无关...

    您的 AVSC 文件需要完全包含所有记录类型。当解析器读取一个文件时,它没有办法知道其他文件

    如果您从 AVDL 文件开始,然后将其转换为 AVSC,则记录会正确嵌入到外部记录中。

    具体来说,

    "fields" :[{
      "name": "keys",
      "type": {
           "type": "record", 
           "namespace": "io.codebrews.schema.test.Keys", 
           ... 
      } 
    }
    

    【讨论】:

    • 是的,我明白了你的意思,在 confluent-kafka 云上手动注册我的模式后,我更新了我的问题,并且在将消息推送到主题时出现错误。有什么方法可以使用它并使其工作使用我的代码,因为 Java 中的许多其他应用程序能够使用该模式并将消息推送到给定主题,因为他们已经在使用它,因此无法更改云上的模式。跨度>
    • Keys 不是有效的 Avro 类型,因此您应该会遇到同样的错误。我需要查看注册表中已有的架构,以告诉您哪些不兼容
    • 不,我刚刚用io.codebrews.schema.test.Keys 手动注册了我的Keys.avsc,用Test.avsc 手动注册了<MY_TOPIC>-value,它给了我新更新的架构问题。就像我在手动注册时没有更改任何 avsc 文件中的任何内容一样。
    • 在添加对引用的支持之前,我停止使用注册表,issues have been posted about it 但 Python 的 avro.load 函数与此无关
    • 是否有相同的python参考,上面的链接看起来像java lib。
    猜你喜欢
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2019-12-21
    • 2019-09-13
    • 2019-07-21
    • 2022-12-27
    • 1970-01-01
    • 2021-10-04
    相关资源
    最近更新 更多