Registering AVRO schema with confluent schema regi

2019-09-11 08:04发布

问题:

Can AVRO schemas be registered with confluent schema registry service ?

As per readme on github https://github.com/confluentinc/schema-registry

Every example uses a JSON schema with a single field and type without any name.

I am trying to store following schema to repository but with different variants getting different error.

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{"type": "record","name": "myrecord","fields": [{"name": "serialization","type": "string"},{"name": "compression","type": "string"},{"name": "encoding","type": "string"},{"name": "data","type": "string"}]}"}' 

Or

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": \"{\"type\": \"record\",\"name\": \"myrecord\",\"fields\": [{\"name\": \"data\",\"type\": \"string\"}]}\"}' http://localhost:8081/subjects/Kafka-key/versions

回答1:

Avro schema can be registered using kafka using below command

curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{\"type\": \"record\",\"name\": \"myrecord\",\"fields\": [{\"name\": \"serialization\",\"type\": \"string\"},{\"name\": \"compression\",\"type\": \"string\"},{\"name\": \"encoding\",\"type\": \"string\"},{\"name\": \"data\",\"type\": \"string\"}]}"}' http://localhost:8081/subjects/Kafka-key/versions 

You are missing some params.

You can use SchemaRegistryHelper to get schema for any id to deserialize data.