繁体   English   中英

Avro 序列化为 Azure EventHub

[英]Avro Serialise to Azure EventHub

I can't find much doco on this topic, but i'm serialising an object to Avro and then sending to Azure EventHub.. I think the Avro needs to contain schema too.. because without, how will a consumer (Ie Azure Stream例如分析)知道如何反序列化?

我可以在线找到的唯一示例使用Microsoft.Hadoop.Avro.Container命名空间..这似乎工作正常,我可以通过 Stream Analytics 读取..但是此代码是否“自动”包含有效负载中的架构? 我确定在这里看不到任何对它的引用:

        using (var memoryStream = new MemoryStream())
        using (var writer = AvroContainer.CreateWriter<T>(memoryStream, Codec.Null))
        using (var seqWriter = new SequentialWriter<T>(writer, items.Count()))
        {
            foreach (var e in items)
            {
                seqWriter.Write(e);
            }

            return memoryStream.ToArray();
        }

Avro in.Net 的格局似乎有点混乱,为什么会有微软特定的 NuGet pkg? 好像很老了,现在是不是被什么东西取代了? 是否有任何关于如何利用标准Apache.Avro NuGet pkg 构建包含架构的有效负载的文档?

Azure 事件中心文档短暂地提到了 Avro,但任何谷歌搜索都只是真正证明事件中心捕获..

无论如何简而言之..有更好的方法吗? 我不认为我可以为此单独发送模式..

First, Azure Stream Analytics support processing events in Avro data formats, you can see it in the offical document Parse JSON and Avro data in Azure Stream Analytics , as the figure below.

在此处输入图像描述

即使假设 Azure Stream Analytics 无法如您所愿反序列化 Avro 格式的事件,您也可以编写自定义 .NET 反序列化器,使其像下面所说的那样工作。

  1. 教程:用于 Azure Stream 分析的自定义 .NET 反序列化器
  2. 对 Azure Stream 分析作业使用 .NET 解串器

同时,我不认为Microsoft.Hadoop.Avro2在您的场景中是适合 Avro 的库。 除了它,还有其他选择

  1. Apache.Avro Its API reference page is https://avro.apache.org/docs/current/api/csharp/html/namespaces.html , and you need to refer to the sample codes for Java or Python to write your C# code .
  2. Microsoft.Avro.Core及其 GitHub rep dougmsft/microsoft-avro带有一些可以参考的测试代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM