问题
I'm using program variables to create configuration objects and loading the schema from a local path which also been registered in kafka.
Creating data object and using "Generic Record" method of serializing.
var logMessageSchema =(Avro.RecordSchema)Avro.Schema.Parse(File.ReadAllText(@"C:\StatusMessageSchema\FileStatusMessageSchema.txt"));
var record = new GenericRecord(logMessageSchema);
record.Add("SystemID", "100");
record.Add("FileName", "ABS_DHCS");
record.Add("FileStatus", "3009");
record.Add("TotalMembers", "400");
record.Add("PlanType", "CA");
record.Add("HippaLevel", "10");
try
{
var dr = await producer.ProduceAsync(topicname, new Message<Null, GenericRecord> { Value = record });
Console.WriteLine($"### Message Published ###\n" + "Topic Name : " + "{0}\n" + "Partition ID : " + "{1}\n" + "Offset ID : " + "{2}\n", dr.Topic, dr.Partition, dr.Offset);
Console.WriteLine();
}
catch (ProduceException<Null, string> e)
{
Console.WriteLine("Delivery failed: {0}", e.Error.Reason);
}
来源:https://stackoverflow.com/questions/57681875/getting-serialization-error-when-publish-message-to-kafka-topic