【发布时间】:2021-11-17 04:55:01
【问题描述】:
我在 kafka 的生产者方面工作,以在主题中推送消息。
我正在使用confluent-kafkaavro producer。
以下是我的架构.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