如何以编程方式从 Python 中的融合模式注册表中获取模式 [英] How to programmatically get schema from confluent schema registry in Python

查看:26
本文介绍了如何以编程方式从 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 中的融合模式注册表中获取模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆