Home > Blockchain >  Use JSON schema in Pubsub topic subscription
Use JSON schema in Pubsub topic subscription

Time:12-16

Can we create Pubsub topic subscription with a json schema and not with a avro schema file? does the file need to be of extension ".avsc"? can we use ".json" instead? Data is avro.

AVSC files contents looks like:

    {
  "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 files contents looks like:

{
"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"
    }]
}

}

Getting the below error when i tried to create subscription with json schema.

enter image description here

CodePudding user response:

Only Avro and Protocol Buffer schemas are supported with Cloud Pub/Sub schemas. The extension of the file does not matter. Note that the Avro schema is valid JSON. The second schema is not a valid AVRO schema, which is why an error is being returned.

  • Related