Use FSharp for Azure WebJob

28/08/2014

I am constantly on the look out for places where F# is a good fit, and I believe that I found one, Azure WebJobs programmed in F#.

Azure WebJobs can be built as console jobs that are scheduled by the Azure WebSite runtime to either run on a predefined schedule or run continuesly. The continuesly running jobs integrates easily with Azure Queues or Blob storage and are designed for doing heavy workloads that you don’t want running in your website. Heavy workload, console jobs all things that F# is really great at.

Here is an example of an Azure WebJob written in F# that listens for messages from a Azure queue named test, and writes it to the output, not exactly a heavy workload but it shows the concept.

To install the nuget package that gives you all the webjob goodness write the following in the package manager console

install-package Microsoft.Azure.WebJobs -prerelease

[fsharp]
open Microsoft.Azure.WebJobs

let ProcessMessage ([<QueueTriggerAttribute(queueName = "test")>] message : string) =
printf "%A" message

[<EntryPoint>]
let main argv =
printfn "%A" argv
use jobHost = new JobHost()
jobHost.RunAndBlock()
0 // return an integer exit code
[/fsharp]

If you need a little more background on Azure WebJobs then check this older version of mine.