[英]Use JSON schema in Pubsub topic subscription
我們可以使用 json 模式而不是 avro 模式文件創建 Pubsub 主題訂閱嗎? 該文件是否需要擴展名為“.avsc”? 我們可以改用“.json”嗎? 數據是avro。
AVSC 文件內容如下所示:
{
"type" : "record",
"name" : "twitter_schema",
"namespace" : "com.miguno.avro",
"fields" : [ {
"name" : "username",
"type" : "string",
"doc" : "Name of the user account on Twitter.com"
}, {
"name" : "tweet",
"type" : "string",
"doc" : "The content of the user's Twitter message"
}, {
"name" : "timestamp",
"type" : "long",
"doc" : "Unix epoch time in seconds"
} ],
"doc:" : "A basic schema for storing Twitter messages"
}
Json 文件內容如下所示:
{
"schema": {
"fields": [{
"name": "username",
"type": "string",
"doc": "Name of the user account on Twitter.com"
}, {
"name": "tweet",
"type": "string",
"doc": "The content of the user's Twitter message"
}, {
"name": "timestamp",
"type": "long",
"doc": "Unix epoch time in seconds"
}]
}
}
當我嘗試使用 json 模式創建訂閱時出現以下錯誤。
Cloud Pub/Sub 架構僅支持 Avro 和 Protocol Buffer 架構。 文件的擴展名無關緊要。 請注意,Avro 模式是有效的 JSON。 第二個模式不是有效的 AVRO 模式,這就是返回錯誤的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.