本文介绍了如何在Python中以编程方式从融合架构注册表中获取架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至目前,我正在做类似此操作的读取avsc文件以获取架构

As of now i am doing something like this reading avsc file to get schema

value_schema = avro.load('client.avsc')

我可以做一些事情来使用主题名从融合架构注册表中获取架构吗?

can i do something to get schema from confluent schema registry using topic-name?

我找到了一种方法,但不知道如何使用它.

i found one way but didn't figure out how to use it.

https://github.com/marcosschroh/python-schema-registry-client

推荐答案

使用 confluent-kafka-python

from confluent_kafka.avro.cached_schema_registry_client import CachedSchemaRegistryClient

sr = CachedSchemaRegistryClient({
    'url': 'http://localhost:8081',
    'ssl.certificate.location': '/path/to/cert',  # optional
    'ssl.key.location': '/path/to/key'  # optional
})

value_schema = sr.get_latest_schema("orders-value")[1]
key_schema= sr.get_latest_schema("orders-key")[1]


使用 SchemaRegistryClient

通过主题名称获取架构

from schema_registry.client import SchemaRegistryClient


sr = SchemaRegistryClient('localhost:8081')
my_schema = sr.get_schema(subject='mySubject', version='latest')

通过ID获取架构

from schema_registry.client import SchemaRegistryClient


sr = SchemaRegistryClient('localhost:8081')
my_schema = sr.get_by_id(schema_id=1)

这篇关于如何在Python中以编程方式从融合架构注册表中获取架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:21