Event hub - Schema registry - Avro Consumer not deserializing using .Net Core

DS 21 Reputation points
2022-08-29T07:20:46.867+00:00

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());  
        }  
Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
627 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.