Search code examples
.netazureapache-kafkaavro

Unable to create schema in schema registry using azure Eventhub


I am using Microsoft.Azure.Data.SchemaRegistry.ApacheAvro 1.0.0-beta1 and I'm trying to send event to the eventhub, using avro schema, but some some reason azure response is BadRequest: Code":400,"Detail":"Schema validation failed: Error parsing undefined value Path 'u0022typeu0022', line 1, position 17. I am using Microsoft provided examples, but I have no luck with them too.

GenericRecord record = GetRecord(message);
EventData data = new EventData(new BinaryData(record, avroSerializer, typeof(GenericRecord)));

record = {Schema: {"type":"record","name":"TestSchema","namespace":"JA.Dto.Kafka.TestSchema","fields":[{"name":"Name","type":"string"}]}, contents: { Name: Hello world, }}

The avroSerializer is SchemaRegistryAvroObjectSerializer, registered with schema registry client, schema group name and auto register schemas is allowed.

In azure portal I tried with and without registering the schema.

Stack trace is: at Azure.Data.SchemaRegistry.SchemaRestClient.Register(String groupName, String schemaName, SerializationType xSchemaType, String schemaContent, CancellationToken cancellationToken) at Azure.Data.SchemaRegistry.SchemaRegistryClient.RegisterSchema(String groupName, String schemaName, SerializationType serializationType, String schemaContent, CancellationToken cancellationToken) at Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.SchemaRegistryAvroObjectSerializer.GetSchemaId(Schema schema, CancellationToken cancellationToken) at Microsoft.Azure.Data.SchemaRegistry.ApacheAvro.SchemaRegistryAvroObjectSerializer.Serialize(Stream stream, Object value, Type inputType, CancellationToken cancellationToken) at Azure.BinaryData..ctor(Object serializable, ObjectSerializer serializer, Type type) at ****\EventHub.AvroProducer`1.d__4.MoveNext() in ***\AvroProducer.cs:line 47

Regards.


Solution

  • The original version of the client is broken. Microsoft.Azure.Data.SchemaRegistry.ApacheAvro 1.0.0-beta1 has a dependency on the original client version. If you download Azure.Data.SchemaRegistry 1.0.0-beta2 (updated client) separately, it'll fix the issue. Just add that version to your project and you should be fine. 🙂