Azure Stream Analytics能否读取Bond序列化事件?咨询转换方案
Since Bond is a Microsoft-built serialization format, you’ve got a couple of straightforward ways to bridge the gap between your Bond-formatted Event Hub data and Azure Stream Analytics (ASA)—which only supports JSON/Avro/CSV natively. Here are the most practical approaches for your POC:
Option 1: Use an Azure Function as a Transformation Proxy
This is a low-code, flexible approach that adds a lightweight middle layer to convert Bond data into an ASA-compatible format before it reaches your stream analytics job.
How it works:
- Create an Azure Function with an Event Hub trigger pointing to your existing Bond-formatted Event Hub.
- In the function code, use the official Bond .NET library to deserialize the incoming event bytes into a .NET object.
- Serialize that object into JSON (the easiest format for ASA) using a library like
Newtonsoft.Json. - Send the transformed JSON data to a new, dedicated Event Hub (this will be the input for your ASA job).
- Configure your ASA job to read from this new Event Hub (using JSON serialization) and output to Blob Storage as planned.
Sample code snippet (C#):
using System; using System.Text; using Microsoft.Azure.EventHubs; using Microsoft.Azure.WebJobs; using Newtonsoft.Json; using Bond; using Bond.Protocols; public static async Task Run(EventData myEventHubMessage, IAsyncCollector<string> outputEventHub, ILogger log) { // Deserialize Bond data var input = new InputBuffer(myEventHubMessage.Body.Array); var deserializer = new Deserializer<SimpleBinaryReader, MyBondDataType>(typeof(MyBondDataType)); var bondData = deserializer.Deserialize(input); // Convert to JSON var jsonData = JsonConvert.SerializeObject(bondData); // Send to target Event Hub for ASA await outputEventHub.AddAsync(jsonData); }Key notes: Make sure to include the
BondandBond.RuntimeNuGet packages in your Function project, and configure the output binding to point to your new Event Hub.
Option 2: Implement a Custom ASA Deserializer
If you want to avoid adding an extra Event Hub and keep your pipeline tighter, ASA supports custom deserializers written in C#. This lets ASA directly read and process your Bond-formatted data.
How it works:
- Create a .NET Class Library project that implements ASA's
IDeserializer<T>interface. - In the deserializer logic, use the Bond library to parse the incoming byte stream into a .NET object that ASA can process (e.g., a strongly-typed class or dynamic object).
- Compile the project into a DLL, along with all required dependencies (Bond libraries included), and package them into a ZIP file.
- In your ASA job's input configuration, select "Custom" as the serialization format, then upload your ZIP file.
- Configure the rest of your ASA job (output to Blob Storage) as usual—ASA will now natively handle your Bond data.
- Create a .NET Class Library project that implements ASA's
Sample deserializer code:
using System; using Microsoft.Azure.StreamAnalytics; using Bond; using Bond.Protocols; public class BondDeserializer : IDeserializer<MyBondDataType> { public MyBondDataType Deserialize(Stream stream) { var input = new InputBuffer(stream); var deserializer = new Deserializer<SimpleBinaryReader, MyBondDataType>(typeof(MyBondDataType)); return deserializer.Deserialize(input); } public void Dispose() { } }Key notes: Ensure your project targets a .NET Framework version compatible with ASA (currently .NET Framework 4.7.2), and test the deserializer locally using ASA's local testing tools before deploying.
Option 3: Directly Write to Blob Storage via Azure Function (Skip ASA)
If your POC doesn't strictly require ASA (e.g., you just need to ingest Bond data into Blob Storage), you can skip ASA entirely: use an Azure Function to read Bond data from Event Hub, deserialize it, and write the transformed data (as JSON/Avro/CSV) directly to Blob Storage. This cuts out the middleman and simplifies your pipeline.
内容的提问来源于stack exchange,提问作者Zorik

