Skip to content

Instantly share code, notes, and snippets.

@snobu
Last active February 19, 2017 13:33
Show Gist options
  • Select an option

  • Save snobu/c05da15bf040afb22736f3602cb503cf to your computer and use it in GitHub Desktop.

Select an option

Save snobu/c05da15bf040afb22736f3602cb503cf to your computer and use it in GitHub Desktop.
FuncApp-DocDB-Binding
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "myEventHubMessage",
"direction": "in",
"path": "marioevents",
"connection": "breakingnews"
},
{
"type": "documentDB",
"name": "outputDocument",
"databaseName": "marioeventsdb",
"collectionName": "MarioCollection",
"createIfNotExists": true,
"connection": "seriously_DOCUMENTDB",
"direction": "out"
}
],
"disabled": false
}
#r "Newtonsoft.Json"
using System;
using Newtonsoft.Json;
public static void Run(string myEventHubMessage, ICollector<object> outputDocument, TraceWriter log)
{
log.Info($"Event: {myEventHubMessage}");
var msg = JsonConvert.DeserializeObject<MarioEvent>(myEventHubMessage as string);
// Write to DocumentDB
outputDocument.Add(
new MarioEvent() {
DeviceId = msg.DeviceId,
Application = msg.Application,
Event = msg.Event
});
}
public class MarioEvent
{
public string DeviceId { get; set; }
public string Application { get; set; }
public string Event { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment