Event hub - Schema registry - Avro Consumer not deserializing using .Net Core
Hello,
I am trying to de-serialize event hub event which is Avro based.
I have written code based on the article (https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/schemaregistry/Microsoft.Azure.Data.SchemaRegistry.ApacheAvro) but event is not getting de-serialized.
Also, there is no error or exception. Any pointer on this is really helpful.
try
{
// Create a producer client that you can use to send events to an event hub
EventHubConsumerClient consumerClient = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, connectionString, eventHubName);
// Create a schema registry client that you can use to serialize and validate data.
var schemaRegistryClient = new SchemaRegistryClient(schemaRegistryEndpoint, credential: new DefaultAzureCredential());
var serializer = new SchemaRegistryAvroSerializer(schemaRegistryClient, schemaGroup, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true });
await foreach (PartitionEvent receivedEvent in consumerClient.ReadEventsAsync())
{
MessageContent msgContent = new MessageContent();
msgContent.Data = receivedEvent.Data.EventBody;
msgContent.ContentType = "avro/binary+schemaId";
var deserialized = (Shipment) await serializer.DeserializeAsync(msgContent, typeof(Shipment));
Console.WriteLine(deserialized.ordernumber);
Console.WriteLine(deserialized.shipmentnumber);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}