Stream Analytics Tools for Visual Studio came out a couple months ago (here) and today I got a chance to try it out to prep some work for a project I am on.
After getting the tools and making sure I am ready to go I wanted to build and run the job locally, this required that I provide a local input file. My input in this case is stream from an event hub.
If you already setup an input points to an event in the stream analytics job using Azure Portal, you can use the Input Details blade in the portal to download sample data:
- Click on Sample Data button
- Select date range for data sample and click OK
- Wait …
- Once you get the notification that data is ready, click on the notification and download the data file.
Or, you can use Service Bus Explorer to prepare an events data file based on real events coming into the event hub:
- Connect to Event Hub
- Create a listener on the consumer group, I created a consumer group just for this purpose
- On the events tab, select all events in the list
- Right click on the selected events and click “Save Selected Events”
Now I needed to prep the saved file in a format that ASA project will accept as a valid local input, for that I processed the content of the file into a new one using the following code:
string filePath = ConfigurationManager.AppSettings.Get("eventfile");
string jsonData = File.ReadAllText(filePath);
var eventsArray = JArray.Parse(jsonData);
var streamwriter = File.AppendText(ConfigurationManager.AppSettings.Get("outputfile"));
foreach (var item in eventsArray)
Back to the Stream Analytics project in Visual Studio, Add a new item of type “Local Input” and point it to the output file with the processed content.
With this, I can develop and test stream analytics jobs locally using real data captured from event hub.