简体   繁体   English

是否可以使用 AVRO 为 Kafka 中的 Google Pub/Sub 主题定义模式?

[英]Is it possible to define a schema for Google Pub/Sub topics like in Kafka with AVRO?

As far as I know, we can define AVRO schemas on Kafka and the topic defined with this schema will only accept the data matching with that schema.据我所知,我们可以在 Kafka 上定义 AVRO 模式,使用该模式定义的主题将只接受与该模式匹配的数据。 It's really useful to validate data structure before accepting into the queue.在接受进入队列之前验证数据结构非常有用。

Is there anything similar in Google Pub/Sub? Google Pub/Sub 中有类似的东西吗?

Kafka itself is not validating a schema, and topics therefore do not inherently have schemas other than a pair of byte arrays plus some metadata. Kafka 本身并不验证模式,因此主题本身没有模式,除了一对字节数组和一些元数据。 It's the serializer that's part of the producing client that performs the validation before the data reaches the topic.序列化程序是生产客户端的一部分,在数据到达主题之前执行验证。 Similarly in PubSub, at the end of the day, it is only storing/sending byte[] data.同样在 PubSub 中,在一天结束时,它只存储/发送byte[]数据。

Therefore, in theory, it's completely feasible to use something similar to the Confluent Avro Schema Registry on either end of the data that moves through PubSub.因此,理论上,在通过 PubSub 移动的数据的任一端使用类似于 Confluent Avro Schema Registry 的东西是完全可行的。 Google does not offer such a feature, AFAIK, so you would need to recreate said service that can perform your Avro compatibility checks, plus tie a PubSub serialization+producer client around that service's client. Google 不提供这样的功能 AFAIK,因此您需要重新创建可以执行 Avro 兼容性检查的服务,并在该服务的客户端周围绑定一个 PubSub 序列化+生产者客户端。 For instance, you can run the Registry itself as a container in GKE to begin with.例如,您可以首先将 Registry 本身作为 GKE 中的容器运行。

Might want to check out Avro message for Google Cloud Pub-Sub?可能想查看Google Cloud Pub-Sub 的 Avro 消息?

Yes, you can use schemas to validate Google Cloud Pub/Sub topics and messages.是的,您可以使用架构来验证 Google Cloud Pub/Sub 主题和消息。

See the docs here .请参阅此处的文档。 AVRO and Protobuf are supported.支持 AVRO 和 Protobuf。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM