我想使用avro模式向kafka发布一条消息,并且在注册的模式中包含枚举类型。
架构:
var s = (RecordSchema)RecordSchema.Parse(
@"{
""type"": ""record"",
""name"": ""xyz"",
""namespace"": ""abc.xyz.com"",
""fields"": [
{
""name"": ""firstname"",
""type"": ""string""
},
{
""name"": ""language"",
""type"": {
""type"": ""enum"",
""name"": ""Language"",
""symbols"": [
""English"", ""Spanish""
]
}
}
}"
);
var record = new GenericRecord(s);
var language = (EnumSchema)EnumSchema.Parse(@"{""type"": ""enum"",""name"": ""Language"",""symbols"": [""English"", ""Spanish""]}");
record.Add("firstname", "xyz");
record.Add("language", new GenericEnum(language, "English"));
但当我试图发布这个消息时,它给了我一个例外。
await producer
.ProduceAsync(topicName, new Message<string, GenericRecord> { Key = "123", Value = record })
.ContinueWith(task => Console.WriteLine(
task.IsFaulted
? $"error producing message: {task.Exception.Message}"
: $"produced to: {task.Result.TopicPartitionOffset}"));
例外情况:
Confluent.Kafka.ProduceException`2: 'Local: Value serialization error'
Inner Exception:
AvroException: GenericEnum required to write against enum schema but found Avro.Generic.GenericEnum in field language
暂无答案!
目前还没有任何答案,快来回答吧!