Date post: | 16-Apr-2017 |
Category: |
Technology |
Upload: | samrat-saha |
View: | 80 times |
Download: | 0 times |
Presented By
WELCOME
MKEDOTNET
Rapid prototyping using Azure Functions - A Walk on the Wild Side
Samrat Saha08.29.2016
SMS Based Survey SystemUsers can text responses to a questionUsers can opt in/out along with preferencesTopics that are time basedAutomatic detection of topicStart with a POC
4
Traditional ApproachWay 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
10
host.json● Runtime specific config: Impacts entire function app● Can set function timeouts, overall behaviors like service bus
settings{
"functionTimeout": "00:10:00"
}
11
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}
12
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);}
13
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
14
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
15
Function Chaining● Call a function from another● Message Queue allows for decoupling● Allows for semi-pure functional programming
16
Where does this leave us?● Prototype being worked on (for this example)● People loved it...got sold to a client
17
18
ThanksCentareLC
19