Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 10804

Extensible Triggers and Binders with Azure WebJobs SDK 1.1.0-alpha1

$
0
0

This release opens a new extensibility model of the SDK which allows you to write custom Triggers and Binders such as Trigger functions on File events, schedule and more. It leads to simplicity in developing and managing WebJobs, since you can now have a single WebJob with functions which can be triggered on Azure Queues, Blobs, Service Bus, Files, Timers and more.

The SDK is also open sourced and the source code is available https://github.com/Azure/azure-webjobs-sdk

Downloads in this Release

You can download the WebJobs SDK from the NuGet gallery and can install these packages from the NuGet gallery using the NuGet Package Manager Console, like this:

Install-Package Microsoft.Azure.WebJobs -pre

If you want to use Microsoft Azure Service Bus, install the following package:

Install-Package Microsoft.Azure.WebJobs.ServiceBus -pre

There is a new package which has some new triggers and binders built on the new extensibility model.

Install-Package Microsoft.Azure.WebJobs.Extensions -pre

Extensible model for Triggers and Binders

The initial release of the SDK was focused on triggering functions based on events from Azure Queues, Blobs and Service Bus. Since the release of the SDK, we have received lots of feedback that developers would like to add more triggers such as triggering a function based on file events, schedule based triggers, events from SQL server and more.

The new extensibility model allows extension authors to write new triggers / binders, and those extensions can be used by others in their applications. It leads to simplicity in developing WebJobs, since now you can have a single WebJob with functions which can be triggered on Azure Queues, Blobs, Service Bus, Files, Timers and more. It also improves the deployment, management and debugging since you are managing a single WebJob.

You can scale your WebJob or host to multiple hosts and the Triggers ensure that only one instance of the function gets invoked.

You get all the benefits of the Core SDK functionality such as dashboard monitoring, route pattern matching, serialization, etc as outlined in this getting started tutorial.

Write a Custom Trigger/ Binder

We have created a new open source repo (https://github.com/Azure/azure-webjobs-sdk-extensions ) which contains extensions demonstrating the new extensibility model.

Please follow this detailed guide on the architecture of the extensibility model. There is a sample which you can use to get started with writing your own Trigger or Binder.

We’re looking for feedback on the new extensibility model so please provide feedback as you write extensions.

Trigger and Binder for Files and Timers

The extensions repo has examples of a File and Timer trigger which demonstrate the new extensibility model. Please note that these are in preview right now.

The following code shows how you can trigger functions based on File events or on a schedule. You need to install Microsoft.Azure.WebJobs.Extensions NuGet package.

    public class Program
    {
        static void Main(string[] args)
        {
            JobHostConfiguration config = new JobHostConfiguration();
            FilesConfiguration filesConfig = new FilesConfiguration();
            if (string.IsNullOrEmpty(filesConfig.RootPath))
            {
                // When running locally, set this to a valid directory. Remove this line when running in Azure.
                // filesConfig.RootPath = @"c:\temp\files";
            };

            // Add Triggers and Binders for Files and Timer Trigger.
            config.UseFiles(filesConfig);
            config.UseTimers();
            JobHost host = new JobHost(config);
            host.RunAndBlock();
        }

        // Function triggered by a timespan schedule every 15 sec.
        public static void TimerJob([TimerTrigger("00:00:15")] TimerInfo timerInfo, TextWriter log)
        {
            log.WriteLine("Scheduled job fired!");
        }

        // When new files arrive in the "import" directory, they are uploaded to a blob container.
        public static void ImportFile(
            [FileTrigger(@"import\{name}","*.txt")] TextReader input,
            [Blob(@"processed/{name}")] TextWriter output,
            string name, TextWriter log)
        {
            output.Write(input.ReadToEnd());
            log.WriteLine(string.Format("Processed input file '{0}'!", name));
        }
    }

 

Dashboard for monitoring extensible Triggers/ Binders

As an extension author you can get all the benefits of the dashboard for monitoring your functions.

You get all the dashboard functionality such as function execution details, Invoke & replay, Causality of functions, Abort, Search blobs for free.

Following screen shot shows the function execution details for the File trigger.

invocationdetails

Other Changes in this Release

Apart from opening up the extensibility model to allow authors to write custom triggers and binders, we fixed key issues reported by customers.

Following are some of the issues fixed in this preview. For the full list, see this query.

Allow user configuration of CloudQueue/CloudQueueClient

Specify permissions needed for ServiceBus Topic

Support configurable retry policies

Changes to ServiceBus registration

As part of opening up the extensibility model, we moved ServiceBus triggers and binders to be based off this new extensibility system. If you are using ServiceBus and you update to this version of the SDK, you will have to register ServiceBus triggers and binders as follows.

Service Bus connection string override is now provided by ServiceBusConfiguration. Please refer to the following sample.

public class Program

{

public static void Main()

{

JobHostConfiguration config = new JobHostConfiguration();

config.UseServiceBus();

JobHost host = new JobHost(config);

host.RunAndBlock();

}

}

Open Source

The source code for the SDK, extensibility system and related repos is available here:

https://github.com/Azure/azure-webjobs-sdk/

https://github.com/Azure/azure-webjobs-sdk-extensions

https://github.com/Azure/azure-webjobs-sdk-samples/

Please do open issues for any feedback and send PR’s for any issues that you want to fix. We are looking forward to different types of Triggers and Binders that you are interested in adding.

Samples

Samples for WebJobs SDK can be found at https://github.com/Azure/azure-webjobs-sdk-samples

Samples for WebJobs SDK extensibility can be found at https://github.com/Azure/azure-webjobs-sdk-extensions

  • You can find samples on how to use triggers and bindings for blobs, tables, queues and Service Bus.
  • PhluffyShuffy which is an Image processing Website where a customer can upload pictures which will trigger a function to process those pictures from blob storage.
  • PhluffyLogs is an example where a WebJob parses log files generated by the app and archives the log files.

Updates in this Release

Documentation

Give feedback and get help

If you have questions, you can ask them on the Azure forum, the ASP.NET forum, or StackOverflow.com. Use #AzureWebJobs SDK for Twitter and the tag Azure-WebJobsSDK for StackOverflow.

Summary

This preview of the SDK opens up a whole new world of Triggers and Binders enabling extension authors to write Triggers for any event type they choose. Examples include File events, Timer/Cron schedule events, SQL events, Redis pub/sub events, etc. Triggers are no longer bound to Azure events only – you can write a Trigger that monitors any event source you choose. It will make developing and managing apps based on triggers a lot easier. We are looking forward to seeing new triggers and binders being written by the community and feedback around the extensibility model.


Viewing all articles
Browse latest Browse all 10804

Trending Articles