Presented
By
WELCOME
MKEDOTNET
Rapid prototyping using Azure Functions -
A Walk on the Wild Side
Samrat Saha
08.29.2016
SMS Based Survey System
Users can text responses to a question
Users can opt in/out along with preferences
Topics that are time based
Automatic detection of topic
Start with a POC
4
Traditional Approach
Way too many ways to skin this cat - prime concern is infrastructure
5
Cloud Approach
● On-Demand
● Horizontal Scaling
● Paradigms (Paxos, Consistent Hashing, Redundancies, SLA’S!)
● Azure
6
7
Azure Functions
● Event driven on demand compute resources
● Serverless Architecture
● WebJobs SDK as a Service
● A function runs in the context of a Function App
8
Bindings
● Triggers: HTTP, Events, Queues
● Input: Blob Storage, Table Storage, DocumentDB
● Output
9
Function App Folder Structure
● WWWRoot
○ host.json
○ function1
• run.csx
• function.json
• bin
○ function 2
• run.csx
• function.json
• Bin
○ sharedAssemblies
• usefulAssembly.dll
1
host.json
● Runtime specific config: Impacts entire function app
● Can set function timeouts, overall behaviors like service bus settings
{
"functionTimeout": "00:10:00"
}
1
function.json
{
"bindings": [
{
"name": "queueItem",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "lc_incoming_sms_queue",
"connection": "lc_incoming_sms_read_connection",
"accessRights": "Listen"
},
{
"type": "serviceBus",
"name": "outputSbMsg",
"queueName": "lc_bluemix_results_queue",
"connection": "lc_bluemix_results_manage_connection",
"accessRights": "Manage",
"direction": "out"
}
],
"disabled": false
}
1
run.csx
#r "../sharedAssemblies/LC-SMS-Quote-DomainModel.dll"
using System;
using System.Threading.Tasks;
using LC_SMS_DomainModel;
using LC_SMS_DomainModel.AzureLogging;
private static TraceWriter _logger;
public static void Run(string queueItem, out string outputSbMsg, TraceWriter log)
{
_logger = log;
log.Info($"C# ServiceBus queue trigger function processed message: {queueItem}");
AzureLogger.InfoCallback = new AzureLogger.InfoDelegate(InfoDelegate);
LCSMSDomainModel domainModel = new LCSMSDomainModel();
domainModel.Init();
String response = domainModel.HandleIncomingSMS(queueItem);
outputSbMsg = response;
}
public static void VerboseDelegate(String message, String source){
_logger.Verbose(message);
}
public static void InfoDelegate(String message, String source=null){
_logger.Info(message);
}
1
Leveraging External Assemblies
● Some namespaces like System automatically imported
● Framework assemblies (automatically available through Azure Functions
Hosting Environment)
#r “System.Web.Http"
● bin folder relative to function
#r “functionSpecificUsefuldll.dll"
● Shared assemblies in under webroot, accessible by relative path
#r "../sharedAssemblies/LC-SMS-Quote-DomainModel.dll"
● Inside assembly to access config:
String storageAccountId = Environment.GetEnvironmentVariable(CONFIG_STORAGE_ACCOUNT,EnvironmentVariableTarget.Process);
● Use Project.Json for NuGet
1
Scaling
● App Service Plan: Dedicated VM, leverage under utilized resources, good for
long running
● Dynamic Service Plan: Function app instance...more instances can be added
dynamically. Best use for intermittent/ short running
● Parallel Execution: Single threaded function runtime-> Scale to multiple
1
Function Chaining
● Call a function from another
● Message Queue allows for decoupling
● Allows for semi-pure functional programming
1
Where does this leave us?
● Prototype being worked on (for this example)
● People loved it...got sold to a client
1
1
Thanks
Centare
LC
1

Rapid prototyping using azure functions - A walk on the wild side

  • 1.
  • 3.
    Rapid prototyping usingAzure Functions - A Walk on the Wild Side Samrat Saha 08.29.2016
  • 4.
    SMS Based SurveySystem Users can text responses to a question Users can opt in/out along with preferences Topics that are time based Automatic detection of topic Start with a POC 4
  • 5.
    Traditional Approach Way toomany ways to skin this cat - prime concern is infrastructure 5
  • 6.
    Cloud Approach ● On-Demand ●Horizontal Scaling ● Paradigms (Paxos, Consistent Hashing, Redundancies, SLA’S!) ● Azure 6
  • 7.
  • 8.
    Azure Functions ● Eventdriven on demand compute resources ● Serverless Architecture ● WebJobs SDK as a Service ● A function runs in the context of a Function App 8
  • 9.
    Bindings ● Triggers: HTTP,Events, Queues ● Input: Blob Storage, Table Storage, DocumentDB ● Output 9
  • 10.
    Function App FolderStructure ● WWWRoot ○ host.json ○ function1 • run.csx • function.json • bin ○ function 2 • run.csx • function.json • Bin ○ sharedAssemblies • usefulAssembly.dll 1
  • 11.
    host.json ● Runtime specificconfig: Impacts entire function app ● Can set function timeouts, overall behaviors like service bus settings { "functionTimeout": "00:10:00" } 1
  • 12.
    function.json { "bindings": [ { "name": "queueItem", "type":"serviceBusTrigger", "direction": "in", "queueName": "lc_incoming_sms_queue", "connection": "lc_incoming_sms_read_connection", "accessRights": "Listen" }, { "type": "serviceBus", "name": "outputSbMsg", "queueName": "lc_bluemix_results_queue", "connection": "lc_bluemix_results_manage_connection", "accessRights": "Manage", "direction": "out" } ], "disabled": false } 1
  • 13.
    run.csx #r "../sharedAssemblies/LC-SMS-Quote-DomainModel.dll" using System; usingSystem.Threading.Tasks; using LC_SMS_DomainModel; using LC_SMS_DomainModel.AzureLogging; private static TraceWriter _logger; public static void Run(string queueItem, out string outputSbMsg, TraceWriter log) { _logger = log; log.Info($"C# ServiceBus queue trigger function processed message: {queueItem}"); AzureLogger.InfoCallback = new AzureLogger.InfoDelegate(InfoDelegate); LCSMSDomainModel domainModel = new LCSMSDomainModel(); domainModel.Init(); String response = domainModel.HandleIncomingSMS(queueItem); outputSbMsg = response; } public static void VerboseDelegate(String message, String source){ _logger.Verbose(message); } public static void InfoDelegate(String message, String source=null){ _logger.Info(message); } 1
  • 14.
    Leveraging External Assemblies ●Some namespaces like System automatically imported ● Framework assemblies (automatically available through Azure Functions Hosting Environment) #r “System.Web.Http" ● bin folder relative to function #r “functionSpecificUsefuldll.dll" ● Shared assemblies in under webroot, accessible by relative path #r "../sharedAssemblies/LC-SMS-Quote-DomainModel.dll" ● Inside assembly to access config: String storageAccountId = Environment.GetEnvironmentVariable(CONFIG_STORAGE_ACCOUNT,EnvironmentVariableTarget.Process); ● Use Project.Json for NuGet 1
  • 15.
    Scaling ● App ServicePlan: Dedicated VM, leverage under utilized resources, good for long running ● Dynamic Service Plan: Function app instance...more instances can be added dynamically. Best use for intermittent/ short running ● Parallel Execution: Single threaded function runtime-> Scale to multiple 1
  • 16.
    Function Chaining ● Calla function from another ● Message Queue allows for decoupling ● Allows for semi-pure functional programming 1
  • 17.
    Where does thisleave us? ● Prototype being worked on (for this example) ● People loved it...got sold to a client 1
  • 18.
  • 19.