【问题标题】:Is it possible to create Avro schema for Dictionary object是否可以为 Dictionary 对象创建 Avro 架构
【发布时间】:2021-07-19 09:23:57
【问题描述】:

尝试在 .net 中为 kafka 消息实现 avro 序列化和反序列化。消息模型如下。

public class SampleMessage
{
    public string Hash{ get; set; }
    public string FileName { get; set; }
    public string Data { get; set; }
    public Dictionary<string, string> Content { get; set; }
    public string LineDetails { get; set; }
}

那么,是否可以在 c# 中为 Dictionary 创建 Avro 架构?

【问题讨论】:

    标签: c# .net avro confluent-platform avro-tools


    【解决方案1】:

    是的。为此,您应该使用复杂类型“map”(https://avro.apache.org/docs/current/spec.html#Maps

    地图使用类型名称“地图”并支持一个属性:

    values:地图值的架构。

    映射 keys 被假定为字符串。

    举个例子,你的 .avsc 看起来像这样:

    {
        "type": "record",
        "name": "SampleMessage",
        "namespace": "samplemessage",
        "fields": [
            {
                "name": "hash",
                "type": "string"
            },
            {
                "name": "fileName",
                "type": "string"
            },
            {
                "name": "data",
                "type": "string"
            },
            {
                "name": "content",
                "type": {
                    "type": "map",
                    "values": "string"
                }
            },
            {
                "name": "lineDetails",
                "type": "string"
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-11
      • 2016-08-24
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多