Skip to main content

Go Go Azure Functions!

11 min read

 

 Azure Functions are cool.  Functions are conceptually similar to WebJobs in that they are event-driven (triggered) and can be easily integrated with other Azure resources.  Functions are a lightweight alternative to rapidly building and deploying event-driven microservices (several jump start templates are available - see the list at the bottom of this post).  Like most microservices, Functions should be stateless and idempotent.

 With Azure Functions, your applications scale based on demand and you pay only for the resources you consume (e.g. "serverless"). It’s important to note here that the Consumption Pricing Tier (which is the default) imposes a 5 minute time limit on your Functions. If your Function needs more than 5 min to execute you’ll need to host your Function on an App Service VM (although you probably shouldn’t be using Functions if your process needs more than 5 minutes to execute - check out Functions Best Practices).  

 Azure Functions can be implemented in multiple programming lanugages and all the code is available on GitHub:

 To learn more about Azure Functions, see the Azure Functions Overview.

 Function Proxies

 Azure Function Proxies were announced as a preview last week.  Function Proxies enable you to define a single API across multiple Functions. You can learn more about Azure Function Proxies here.

Function Proxies vs. API Management - What to Use When?

I've had a few people express confusion about what to use when: Azure Proxies vs. Azure API Management (APIM).  Azure Function Proxies and APIM can both be used to map a single API to one or more endpoints. Function Proxies make it easier to manage and expose multiple Functions through a simple API while APIM is a full service gateway for documenting, securing, logging and governing the use of your APIs.

 

 

A List of all Function Templates

These templates are available in the Azure Functions Portal.

Core Templates:

BlobTrigger-CSharp - A C# function that will be run whenever a blob is added to a specified container

BlobTrigger-FSharp - An F# function that will be run whenever a blob is added to a specified container

BlobTrigger-JavaScript - A JavaScript function that will be run whenever a blob is added to a specified container

EventHubTrigger-CSharp - A C# function that will be run whenever an event hub receives a new event

EventHubTrigger-FSharp - An F# function that will be run whenever an event hub receives a new event

EventHubTrigger-JavaScript - A JavaScript function that will be run whenever an event hub receives a new event

GenericWebHook-CSharp - A C# function that will be run whenever it receives a webhook request

GenericWebHook-FSharp - An F# function that will be run whenever it receives a webhook request

GenericWebHook-JavaScript - A JavaScript function that will be run whenever it receives a webhook request

GitHubWebHook-CSharp - A C# function that will be run whenever it receives a GitHub webhook request

GitHubWebHook-FSharp - An F# function that will be run whenever it receives a GitHub webhook request

GitHubWebHook-JavaScript - A JavaScript function that will be run whenever it receives a GitHub webhook request

HttpTrigger-CSharp - A C# function that will be run whenever it receives an HTTP request

HttpTrigger-FSharp - An F# function that will be run whenever it receives an HTTP request

HttpTrigger-JavaScript - A JavaScript function that will be run whenever it receives an HTTP request

ManualTrigger-CSharp - A C# function that is triggered manually via the portal "Run" button

ManualTrigger-FSharp - An F# function that is triggered manually via the portal "Run" button

ManualTrigger-JavaScript - A JavaScript function that is triggered manually via the portal "Run" button

QueueTrigger-CSharp - A C# function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-FSharp - An F# function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-JavaScript - A JavaScript function that will be run whenever a message is added to a specified Azure Queue Storage

ServiceBusQueueTrigger-CSharp - A C# function that will be run whenever a message is added to a specified Service Bus queue

ServiceBusQueueTrigger-FSharp - An F# function that will be run whenever a message is added to a specified Service Bus queue

ServiceBusQueueTrigger-JavaScript - A JavaScript function that will be run whenever a message is added to a specified Service Bus queue

ServiceBusTopicTrigger-CSharp - A C# function that will be run whenever a message is added to the specified Service Bus topic

ServiceBusTopicTrigger-FSharp - An F# function that will be run whenever a message is added to the specified Service Bus topic

ServiceBusTopicTrigger-JavaScript - A JavaScript function that will be run whenever a message is added to the specified Service Bus topic

TimerTrigger-CSharp - A C# function that will be run on a specified schedule

TimerTrigger-FSharp - An F# function that will be run on a specified schedule

TimerTrigger-JavaScript - A JavaScript function that will be run on a specified schedule

API and Webhooks Templates:

GenericWebHook-CSharp - A C# function that will be run whenever it receives a webhook request

GenericWebHook-FSharp - An F# function that will be run whenever it receives a webhook request

GenericWebHook-JavaScript - A JavaScript function that will be run whenever it receives a webhook request

GitHubWebHook-CSharp - A C# function that will be run whenever it receives a GitHub webhook request

GitHubWebHook-FSharp - An F# function that will be run whenever it receives a GitHub webhook request

GitHubWebHook-JavaScript - A JavaScript function that will be run whenever it receives a GitHub webhook request

HttpTrigger-CSharp - A C# function that will be run whenever it receives an HTTP request

HttpTrigger-FSharp - An F# function that will be run whenever it receives an HTTP request

HttpTrigger-JavaScript - A JavaScript function that will be run whenever it receives an HTTP request

Data Processing Templates:

BlobTrigger-CSharp  - A C# function that will be run whenever a blob is added to a specified container

BlobTrigger-FSharp - An F# function that will be run whenever a blob is added to a specified container

BlobTrigger-JavaScript - A JavaScript function that will be run whenever a blob is added to a specified container

EventHubTrigger-CSharp - A C# function that will be run whenever an event hub receives a new event

EventHubTrigger-FSharp - An F# function that will be run whenever an event hub receives a new event

EventHubTrigger-JavaScript - A JavaScript function that will be run whenever an event hub receives a new event

QueueTrigger-CSharp - A C# function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-FSharp - An F# function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-JavaScript - A JavaScript function that will be run whenever a message is added to a specified Azure Queue Storage

SendGrid-CSharp - (Preview) A C# function that sends a confirmation e-mail when a new item is added to a particular queue

SendGrid-JavaScript - (Preview) A JavaScript function that sends a confirmation e-mail when a new item is added to a particular queue

ServiceBusQueueTrigger-CSharp - A C# function that will be run whenever a message is added to a specified Service Bus queue

ServiceBusQueueTrigger-FSharp - An F# function that will be run whenever a message is added to a specified Service Bus queue

ServiceBusQueueTrigger-JavaScript - A JavaScript function that will be run whenever a message is added to a specified Service Bus queue

ServiceBusTopicTrigger-CSharp - A C# function that will be run whenever a message is added to the specified Service Bus topic

ServiceBusTopicTrigger-FSharp - An F# function that will be run whenever a message is added to the specified Service Bus topic

ServiceBusTopicTrigger-JavaScript - A JavaScript function that will be run whenever a message is added to the specified Service Bus topic

TimerTrigger-CSharp - A C# function that will be run on a specified schedule

TimerTrigger-FSharp - An F# function that will be run on a specified schedule

TimerTrigger-JavaScript - A JavaScript function that will be run on a specified schedule

Sample Templates:

FaceLocator-CSharp - A C# function that processes images and outputs the bounding rectangle of faces

FaceLocator-FSharp - An F# function that processes images and outputs the bounding rectangle of faces

FaceLocator-JavaScript - A JavaScript function that processes images and outputs the bounding rectangle of faces

GitHubCommenter-CSharp - A C# function that will be run whenever it receives a GitHub webhook request

GitHubCommenter-FSharp - An F# function that will be run whenever it receives a GitHub webhook request

GitHubCommenter-JavaScript - A JavaScript function that will be run whenever it receives a GitHub webhook request

HttpGET(CRUD)-CSharp - A C# function that fetches entities from a Storage Table when it receives an HTTP request

HttpGET(CRUD)-FSharp - An F# function that fetches entities from a Storage Table when it receives an HTTP request

HttpGET(CRUD)-JavaScript - A JavaScript function that fetches entities from a Storage Table when it receives an HTTP request

HttpGET(CRUD)-PHP - (Experimental) A PHP function that fetches entities from a Storage Table when it receives an HTTP request

HttpPOST(CRUD)-CSharp - A C# function that adds entities to a Storage Table when it receives an HTTP request

HttpPOST(CRUD)-FSharp - An F# function that adds entities to a Storage Table when it receives an HTTP request

HttpPOST(CRUD)-JavaScript - A JavaScript function that adds entities to a Storage Table when it receives an HTTP request

HttpPUT(CRUD)-CSharp - A C# function that updates entity in a Storage Table when it receives an HTTP request

HttpPUT(CRUD)-FSharp - An F# function that updates entity in a Storage Table when it receives an HTTP request

ImageResizer-CSharp - A C# function that creates resized images whenever a blob is added to a specified container

ImageResizer-FSharp - An F# function that creates resized images whenever a blob is added to a specified container

SasToken-CSharp - A C# function that generates a SAS token for Azure Storage for a given container and blob name

SasToken-FSharp - An F# function that generates a SAS token for Azure Storage for a given container and blob name.

SasToken-JavaScript - (Preview) A JavaScript function that will be run whenever a file is added to a External File provider.

ScheduledMail-CSharp - (Preview) A C# function that will periodically send emails

SendGrid-CSharp - (Preview) A C# function that sends a confirmation e-mail when a new item is added to a particular queue

SendGrid-FSharp - (Preview) An F# function that sends a confirmation e-mail when a new item is added to a particular queue

SendGrid-JavaScript - (Preview) A JavaScript function that sends a confirmation e-mail when a new item is added to a particular queue

Experimental Templates:

BlobTrigger-Batch - (Experimental) A Batch function that will be run whenever a blob is added to a specified container

ExternalFileTrigger-Batch - (Experimental) A Batch function that will be run whenever a file is added to a External File provider.

ExternalFileTrigger-CSharp - (Preview) A C# function that will be run whenever a file is added to a External File provider.

ExternalFileTrigger-FSharp - (Preview) An F# function that will be run whenever a file is added to a External File provider.

ExternalFileTrigger-JavaScript - (Preview) A JavaScript function that will be run whenever a file is added to a External File provider.

ExternalTable-CSharp - (Experimental) A C# function that fetches entities from a External Table when it receives an HTTP request.

ExternalTable-FSharp - (Experimental) An F# function that fetches entities from a External Table when it receives an HTTP request.

HttpTrigger-Batch - (Experimental) A Batch function that will be run whenever it receives an HTTP request

HttpTrigger-Powershell - (Preview) A PowerShell function that will be run whenever it receives an HTTP request

QueueTrigger-Bash - (Experimental) A bash function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-Batch - (Experimental) A Batch function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-Php - (Experimental) A PHP function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-Powershell - (Preview) A PowerShell function that will be run whenever a message is added to a specified Azure Queue Storage

QueueTrigger-Python - (Experimental) A Python function that will be run whenever a message is added to a specified Azure Queue Storage

TimerTrigger-Powershell - (Preview) A PowerShell function that will be run on a specified schedule

 

Drop Dead Simple ASP.NET WebHooks example

1 min read

ASP.NET Webhooks were RTM in late December of last year.  There are a ton of examples from the webhooks available on Github.  There are so many examples it can be somewhat overwhelming. 

I wanted to create the simplest possible demo showing how ASP.NET webhooks work and did so here.  The demo contains a number of comments explaining how to set up and use it.  I hope you find it helpful in learning more about ASP.NET webhooks.

 

 

 

 

Using webhooks in Logic Apps

4 min read

Update: This post was originally written before Logic Apps Designer fully supported webhooks.  Logic Apps Deisgner now fully supports webhooks.

New to webhooks? There is a short intro to webhooks in this post on DZone.  It does a decent job explaining the concept but more interestingly discusses how webhooks are composable.  Wonderful idea.

It's election season here in the US and that means polling.  Polling is fine for voting but is usually not a great idea for services.

If I've got a long-running process (e.g. waiting for a user to login and approve a document) I shouldn't have to poll to see if that process has completed yet. 

Polling is like going on a long drive with a kid in the back seat constantly asking "are we there yet? are we there yet?". 

Adopting an event-driven approach is much more natural and loosely coupled - the long-running process can simply tell us when it's complete instead of periodically polling it.  Being event-driven with RESTful services can be accomplished in many ways but one of the easiest is with webhooks.  A webhook is a user-defined HTTP callback.  I register my callback with the long-running process and wait for it to be invoked by a POST.  No polling needed. 

Webhooks are now supported by Logic Apps.  You can think of an Azure Logic App as a workflow that you build and run in the cloud. With webhooks your workflow can wait for an event from a long-running process. 

Here is a simple Logic App that consists of two steps.  The first step POSTs a simple message to a RequestBin URL. Request Bin is a great, free service you can use to test and inspect HTTP messaging.  The second step is another HTTP action but it has a strange icon on it - it also doesn't render properly in the designer.  This is because webhooks aren’t yet supported in the Logic Apps Designer (this is coming soon).  Webhooks are supported in the code view so let’s look at some code. 

Here is (most of) the code view of our simple Logic App (Logic Apps use JSON under the covers). There are two steps in this workflow.  The first step is named "Http" (default name - I could have changed it but I didn't).  The second step is named "Http_2".  You'll see each step contains an optional set of conditions, inputs and a type identifier.  

Note the second step of the workflow ("Http_2") surrounded by the red box.   Looking at this code we can see some interesting things...

If you look at the inputs you'll see it contains a subscribe construct.  The @listCallbackUrl() enables us to retrieve the URL for firing the webhook (where the long running process can "publish" its event to).  The type has been changed from Http to HttpWebhook.  The URL being used here came from RequestBin.  These changes had to be made manually in code view because the designer doesn't yet support webhooks.  This "Http_2" step originally looked like the "Http" step right above it.

What happens when we run the workflow?  It stops and waits for the webhook we subscribed to:

If we go over to RequestBin we can copy the webhook URL (in red below) and use it to POST back using a tool like Postman or Fiddler (click to enlarge):

Now that the webhook has fired (was POSTed back) the workflow will wake up and continue running:

Learn more about the JSON and commands used by Logic Apps here.

Note: Old-timers like me might be surprised to see "Workflow Definition Language" making a comeback.  Despite the similar acronym this is not the same WIDL that was used by the now defunct webMethods product.  

  

 

Reactive Extensions, SignalR and WebHooks

2 min read

Reactive Extensions is a library for creating/composing streams of data or events. Rx doesn't deal with network connectivity. Rx only deals with Observables and can wrap any collection, stream, event or async method into a common Observable interface.

SignalR is a communications tool for implementing duplex/real-time connections. It works over HTTP and supports long-polling, server-side events and WebSockets.  SignalR requires requires a constant network connection.

WebHooks are user-defined HTTP callbacks that are useful for communicating event notifications across web apps and external services. Event notifications can be "pushed" in near real-time - no need for polling or a constant network connection.

SignalR, Rx and WebHooks are very different but can be used together. For example, when you receive a WebHook notification from PayPal, you could pop up a toast notification to a user on your webapp via SignalR indicating that a payment was been received.

TLDR;

  • Rx helps you specify what happens but doesn't get into the details of how an event can be communicated.  
  • SignalR enables real-time communications of an event but requires a constant network connection.
  • WebHooks also enable real-time communications of an event but is "web friendly" (doesn't require a constant network connection).