Spark(四十五):Schema Registry

很多时候在流数据处理时,我们会将avro格式的数据写入到kafka的topic,但是avro写入到kafka的时候,数据有可能会与版本升级,也就是schema发生变化,此时如果消费端,不知道哪些数据的schema是使用升级前的,哪些数据schema使用升级后,此次消费端一旦就经常会跑出异常,为了避免schema解析时出现异常,就不得不得不使得数据自动过期或者删除kafka的topic(重新新建topic),这样必然会造成数据一部分丢失,而且在生产环境下,升级就变得特别麻烦,而不是希望程序不停止,无感升级。
而schema registry可以解决上班那种情况的问题,每条记录对应schema一都和服务中schema一一关联,消费端可以通过获取记录后就能知道该记录是使用哪个版本的schema,自动获取schema内容进行解析。

Schema Registry目前比较常见的有个框架来实现:

1)Confluent Schema Registry
官网:https://docs.confluent.io/2.0.0/schema-registry/docs/index.html
2)Pulsar Schema
官网:http://pulsar.apache.org/
在2.0版本中,Pulsar引入了对Schema的原生支持。这意味着你可以在创建Pulsar主题的时候定义消息相应的Schema,然后Pulsar会根据你指定的Schema保证发布消息的完整性。2.0版本只支持String,Bytes和JSON三种内置Schema。从2.1版本开始,Pulsar原生支持Avro和Protobuf这两种类型。
Schema将Pulsar从一个只支持非结构化数据的消息系统变成了也支持结构化数据的流数据平台。在接下来的2.2版本中,Schema将作为最重要的基石组件用来实现流数据的可查询化,也就是传说中的Pulsar SQL。
3)Hortonworks registry
官网:https://hortonworks.com/open-source/schema-registry/
Apache NiFi – Records and Schema Registries
http://wp.huangshiyang.com/apache-nifi-records-and-schema-registries
Installing a local Hortonworks Registry to use with Apache NiFi
https://community.hortonworks.com/content/kbentry/119766/installing-a-local-hortonworks-registry-to-use-wit.html
Hortonworks Registry的开发说明文档:
https://registry-project.readthedocs.io/en/latest/schema-registry.html#installation

猜你喜欢

转载自www.cnblogs.com/yy3b2007com/p/10757186.html
今日推荐