将消息发布到KAFKA主题时出现序列化错误

时间:2019-08-27 20:32:25

标签: c# apache-kafka avro kafka-producer-api

我正在使用程序变量来创建配置对象,并从也已在kafka中注册的本地路径加载架构。

创建数据对象并使用“通用记录”方法进行序列化。

                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);
                }

0 个答案:

没有答案