Skip to content

Commit 71ed8a0

Browse files
committedDec 30, 2020
Add instructions for custom deserializer in VS Code
1 parent a911229 commit 71ed8a0

File tree

8 files changed

+130
-16
lines changed

8 files changed

+130
-16
lines changed
 

‎articles/stream-analytics/custom-deserializer.md

Lines changed: 130 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
---
22
title: Tutorial - Custom .NET deserializers for Azure Stream Analytics cloud jobs
3-
description: This tutorial demonstrates how to create a custom .NET deserializer for an Azure Stream Analytics cloud job using Visual Studio.
3+
description: This tutorial demonstrates how to create a custom .NET deserializer for an Azure Stream Analytics cloud job using Visual Studio or Visual Studio Code.
44
author: mamccrea
55
ms.author: mamccrea
66
ms.reviewer: mamccrea
77
ms.service: stream-analytics
88
ms.topic: tutorial
9-
ms.date: 05/06/2019
9+
ms.date: 12/17/2020
1010
---
1111

1212
# Tutorial: Custom .NET deserializers for Azure Stream Analytics
1313

1414
Azure Stream Analytics has [built-in support for three data formats](stream-analytics-parsing-json.md): JSON, CSV, and Avro. With custom .NET deserializers, you can read data from other formats such as [Protocol Buffer](https://developers.google.com/protocol-buffers/), [Bond](https://github.com/Microsoft/bond) and other user defined formats for both cloud and edge jobs.
1515

16-
This tutorial demonstrates how to create a custom .NET deserializer for an Azure Stream Analytics cloud job using Visual Studio.
16+
This tutorial demonstrates how to create a custom .NET deserializer for an Azure Stream Analytics cloud job using Visual Studio or Visual Studio Code.
1717

1818
In this tutorial, you learn how to:
1919

2020
> [!div class="checklist"]
2121
> * Create a custom deserializer for protocol buffer.
22-
> * Create an Azure Stream Analytics job in Visual Studio.
22+
> * Create an Azure Stream Analytics job in Visual Studio or Visual Studio Code.
2323
> * Configure your Stream Analytics job to use the custom deserializer.
24-
> * Run your Stream Analytics job locally to test the custom deserializer.
24+
> * Run your Stream Analytics job locally to test and debug the custom deserializer.
2525
26-
## Prerequisites
26+
27+
## Custom .NET deserializers in Visual Studio
28+
29+
### Prerequisites
2730

2831
* If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2932

30-
* Install [Visual Studio 2017](https://www.visualstudio.com/downloads/) or [Visual Studio 2015](https://www.visualstudio.com/vs/older-downloads/). Enterprise (Ultimate/Premium), Professional, and Community editions are supported. Express edition isn't supported.
33+
* Install [Visual Studio 2019 (recommended)](https://www.visualstudio.com/downloads/) or [Visual Studio 2017](https://www.visualstudio.com/vs/older-downloads/). Enterprise (Ultimate/Premium), Professional, and Community editions are supported. Express edition isn't supported.
3134

32-
* [Install the Stream Analytics tools for Visual Studio](stream-analytics-tools-for-visual-studio-install.md) or update to the latest version. The following versions of Visual Studio are supported:
33-
* Visual Studio 2015
34-
* Visual Studio 2017
35+
* [Install the Stream Analytics tools for Visual Studio](stream-analytics-tools-for-visual-studio-install.md) or update to the latest version.
3536

3637
* Open **Cloud Explorer** in Visual Studio, and sign in to your Azure subscription.
3738

3839
* Create a container in your Azure Storage Account.
3940
The container you create will be used to store assets related to your Stream Analytics job. If you already have a storage account with existing containers, you may use them. If not, you'll need to [create a new container](../storage/blobs/storage-quickstart-blobs-portal.md).
4041

41-
## Create a custom deserializer
42+
### Create a custom deserializer
4243

4344
1. Open Visual Studio and select **File > New > Project**. Search for **Stream Analytics** and select **Azure Stream Analytics Custom Deserializer Project (.NET)**. Give the project a name, like **Protobuf Deserializer**.
4445

@@ -50,13 +51,13 @@ The container you create will be used to store assets related to your Stream Ana
5051

5152
4. Build the **Protobuf Deserializer** project.
5253

53-
## Add an Azure Stream Analytics project
54+
### Add an Azure Stream Analytics project
5455

5556
1. In Solution Explorer, right-click the **Protobuf Deserializer** solution and select **Add > New Project**. Under **Azure Stream Analytics > Stream Analytics**, choose **Azure Stream Analytics Application**. Name it **ProtobufCloudDeserializer** and select **OK**.
5657

5758
2. Right-click **References** under the **ProtobufCloudDeserializer** Azure Stream Analytics project. Under **Projects**, add **Protobuf Deserializer**. It should be automatically populated for you.
5859

59-
## Configure a Stream Analytics job
60+
### Configure a Stream Analytics job
6061

6162
1. Double-click **JobConfig.json**. Use the default configurations, except for the following settings:
6263

@@ -101,22 +102,135 @@ The container you create will be used to store assets related to your Stream Ana
101102
|Class Name|MessageBodyProto.MessageBodyDeserializer|
102103
|Local Input File Path|< the file path for the downloaded sample protobuf input file>|
103104

104-
## Execute the Stream Analytics job
105+
### Execute the Stream Analytics job
105106

106107
1. Open **Script.asaql** and select **Run Locally**.
107108

108109
2. Observe the results in **Stream Analytics Local Run Results**.
109110

110111
You have successfully implemented a custom deserializer for your Stream Analytics job! In this tutorial, you tested the custom deserializer locally. For your actual data, you would properly configure the input and output. Then submit the job to Azure from Visual Studio to run your job in the cloud using the custom deserializer you just implemented.
111112

112-
## Debug your deserializer
113+
### Debug your deserializer
113114

114115
You can debug your .NET deserializer locally the same way you debug standard .NET code.
115116

116117
1. Add breakpoints in your function.
117118

118119
2. Press **F5** to start debugging. The program will stop at your breakpoints as expected.
119120

121+
## Custom .NET deserializers in Visual Studio Code
122+
123+
### Prerequisites
124+
125+
* If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
126+
127+
* Install [Visual Studio Code](https://code.visualstudio.com/Download).
128+
129+
* [Install and activate the Stream Analytics tools for Visual Studio Code](quick-create-visual-studio-code.md)
130+
131+
* Install [.NET Core SDK](https://dotnet.microsoft.com/).
132+
133+
* Create a container in your Azure Storage Account.
134+
The container you create will be used to store assets related to your Stream Analytics job. If you already have a storage account with existing containers, you may use them. If not, you'll need to [create a new container](../storage/blobs/storage-quickstart-blobs-portal.md).
135+
136+
### Create a custom deserializer
137+
138+
1. Open a terminal and run following command to create a .NET class library in Visual Studio Code for your custom deserializer called **ProtobufDeserializer**.
139+
140+
```dotnetcli
141+
dotnet new classlib -o ProtobufDeserializer
142+
```
143+
144+
2. Go to the **ProtobufDeserializer** project directory and install the [Microsoft.Azure.StreamAnalytics](https://www.nuget.org/packages/Microsoft.Azure.StreamAnalytics/) and [Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf/) NuGet packages.
145+
146+
```dotnetcli
147+
dotnet add package Microsoft.Azure.StreamAnalytics
148+
```
149+
150+
```dotnetcli
151+
dotnet add package Google.Protobuf
152+
```
153+
154+
3. Add the [MessageBodyProto class](https://github.com/Azure/azure-stream-analytics/blob/master/CustomDeserializers/Protobuf/MessageBodyProto.cs) and the [MessageBodyDeserializer class](https://github.com/Azure/azure-stream-analytics/blob/master/CustomDeserializers/Protobuf/MessageBodyDeserializer.cs) to your project.
155+
156+
157+
4. Build the **ProtobufDeserializer** project.
158+
159+
### Add an Azure Stream Analytics project
160+
161+
1. Open Visual Studio Code and select **Ctrl+Shift+P** to open the command palette. Then enter ASA and select **ASA: Create New Project**. Name it **ProtobufCloudDeserializer**.
162+
163+
### Configure a Stream Analytics job
164+
165+
1. Double-click **JobConfig.json**. Use the default configurations, except for the following settings:
166+
167+
|Setting|Suggested Value|
168+
|-------|---------------|
169+
|Global Storage Settings Resource|Choose data source from current account|
170+
|Global Storage Settings Subscription| < your subscription >|
171+
|Global Storage Settings Storage Account| < your storage account >|
172+
|CustomCodeStorage Settings Storage Account|< your storage account >|
173+
|CustomCodeStorage Settings Container|< your storage container >|
174+
175+
2. Under **Inputs** folder open **input.json**. Select **Add live input** and add an input from Azure Data Lake Storage Gen2/Blob storage, choose **Select from your Azure subscription**. Use the default configurations, except for the following settings:
176+
177+
|Setting|Suggested Value|
178+
|-------|---------------|
179+
|Name|Input|
180+
|Subscription|< your subscription >|
181+
|Storage Account|< your storage account >|
182+
|Container|< your storage container >|
183+
|Serialization Type|Choose **Custom**|
184+
|SerializationProjectPath|Select **Choose library project path** from CodeLens and select the **ProtobufDeserializer** library project created in previous section. Select **build project** to build the project|
185+
|SerializationClassName|Select **select deserialization class** from CodeLens to auto populate the class name and DLL path|
186+
|Class Name|MessageBodyProto.MessageBodyDeserializer|
187+
188+
![Add custom deserializer input](./media/custom-deserializer/create-input-vscode.png)
189+
190+
191+
3. Add the following query to the **ProtobufCloudDeserializer.asaql** file.
192+
193+
```sql
194+
SELECT * FROM Input
195+
```
196+
197+
4. Download the [sample protobuf input file](https://github.com/Azure/azure-stream-analytics/blob/master/CustomDeserializers/Protobuf/SimulatedTemperatureEvents.protobuf). In the **Inputs** folder, right-click **input.json** and select **Add local input**. Then, double-click **local_input1.json** and use the default configurations, except for the following settings.
198+
199+
|Setting|Suggested Value|
200+
|-------|---------------|
201+
|Select local file path|Click CodeLens to select < The file path for the downloaded sample protobuf input file>|
202+
203+
### Execute the Stream Analytics job
204+
205+
1. Open **ProtobufCloudDeserializer.asaql** and select **Run Locally** from CodeLens then choose **Use Local Input** from the dropdown list.
206+
207+
2. Observe the results in **Results** tab in job diagram view on the right. You can also click the steps in the job diagram to view intermediate result. More details please see [Debug locally using job diagram](debug-locally-using-job-diagram-vs-code).
208+
209+
![Check local run result](./media/custom-deserializer/check-local-run-result-vscode.png)
210+
211+
212+
You have successfully implemented a custom deserializer for your Stream Analytics job! In this tutorial, you tested the custom deserializer locally with local input data. You can also test it [using live data input in the cloud](visual-studio-code-local-run-live-input.md). For running the job in the cloud, you would properly configure the input and output. Then submit the job to Azure from Visual Studio Code to run your job in the cloud using the custom deserializer you just implemented.
213+
214+
### Debug your deserializer
215+
216+
You can debug your .NET deserializer locally the same way you debug standard .NET code.
217+
218+
1. Add breakpoints in your .NET function.
219+
220+
2. Click **Run** from Visual Studio Code Activity bar and select **create a launch.json file**. Choose **ProtobufCloudDeserializer** and then **Azure Stream Analytics** from the dropdown list. Edit the **launch.json** file to replace <ASAScript>.asaql with ProtobufCloudDeserializer.asaql.
221+
222+
![Create launch file](./media/custom-deserializer/create-launch-file-vscode.png)
223+
224+
![Create launch file ](./media/custom-deserializer/create-launch-file-vscode-2.png)
225+
226+
![Configure launch file](./media/custom-deserializer/configure-launch-file-vscode.png)
227+
228+
229+
3. Press **F5** to start debugging. The program will stop at your breakpoints as expected. This works for both local input and live input data.
230+
231+
![Debug custom deserializer](./media/custom-deserializer/debug -vscode.png)
232+
233+
120234
## Clean up resources
121235

122236
When no longer needed, delete the resource group, the streaming job, and all related resources. Deleting the job avoids billing the streaming units consumed by the job. If you're planning to use the job in future, you can stop it and restart it later when you need. If you are not going to continue to use this job, delete all resources created by this tutorial by using the following steps:
@@ -130,4 +244,4 @@ When no longer needed, delete the resource group, the streaming job, and all rel
130244
In this tutorial, you learned how to implement a custom .NET deserializer for the protocol buffer input serialization. To learn more about creating custom deserializers, continue to the following article:
131245

132246
> [!div class="nextstepaction"]
133-
> [Create different .NET deserializers for Azure Stream Analytics jobs](custom-deserializer-examples.md)
247+
> [Create different .NET deserializers for Azure Stream Analytics jobs](custom-deserializer-examples.md)
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)