C# Confluent. Apache .Avro ​​- GenericRecord.Add (схема), имеющая перечисление в схеме - PullRequest
0 голосов
/ 06 августа 2020

Я хочу опубликовать sh сообщение в kafka, используя схему avro и имеющую типы перечисления в зарегистрированной схеме.

Схема:

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

Но когда я пытаюсь опубликовать sh это сообщение вызывает у меня исключение.

    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
...