Search code examples
goavroazure-eventhub

How to fetch the schema from Azure eventhub using Golang


I have schema created in the eventhub, and I'm using "github.com/Azure/azure-event-hubs-go/v3" package to receive and send messages to eventhub using Go.

How can I use Schema to serialize/deserialize the data being sent or received?


Solution

  • Accessing schema doesn't depend on which Messaging queue is being used.

    Inorder to fetch the avro schema we can use the standard net/http package as there are APIs which return the schema.

    The URL would be of the below format:

    If the avro subject and version is known:

    https://<schema_registry_url>/subjects/<subject_name>/versions/<version_number>
    
    If the latest version schema is required `<version_number>` can be replaced with `latest`
    

    If the schema id is known:

    https://<schema_registry_url>/schemas/ids/<id>