Search code examples
c#azure-webjobs.net-4.7.2

Azure WebJobs: Microsoft.Tpl.Dataflow deprecated


I upgraded a few very old nuget packages on my solution and found out that in a console app that I used for Azure Webjob, the package Microsoft.Tpl.Dataflow (I was using v4.5.24) got deprecated. So, I had to go with the Nuget alternate: System.Threading.Tasks.Dataflow, v4.11.0.

Here is my Program.cs:

internal class Program
{
    private static void Main()
    {
        var config = new JobHostConfiguration();
        config.Queues.MaxDequeueCount = Convert.ToInt32(ConfigurationManager.AppSettings["MaxDequeueCount"]);
        config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["MaxPollingInterval"]));
        config.Queues.BatchSize = Convert.ToInt32(ConfigurationManager.AppSettings["BatchSize"]); ;
        config.NameResolver = new QueueNameResolver();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost();
        host.RunAndBlock();
    }
}
  • The new JobHostConfiguration() is now gone
  • new JobHost() expects two parameters now
  • host.RunAndBlock() is gone

Another issue was the QueueTrigger was also not found but a separate package helped out there: Microsoft.Azure.WebJobs.Extensions.Storage, v3.0.10

This is a classic .Net 4.7.2 Class library project. I'm looking at the documentation for the two parameters for `new JobHost()' and I sense .Net Core. Am I at a deadlock now? How do I convert the Program.cs to make it work?


Solution

  • Suppose you upgrade your web job package from v1 to v3, mostly the configuration you could refer to the official tutorial:Get started with the Azure WebJobs SDK for event-driven background processing.

    And about the queue trigger webjob, the v3 webjob you must explicitly install the Storage binding extension, more details you could refer to here:Install the Storage binding extension.

    Then is about the queue trigger webjob configuration, if you want to set the batch size .etc, you could refer to:Queue storage trigger configuration. Mostly your problem you could get the answer from the tutorial or other documents.

    The below is my sample code about net 472 webjob.

    This is my webjob package and version. With the v3 webjob, the dependency has a System.Threading.Tasks.Dataflow (>= 4.8.0) so install Microsoft.Azure.WebJobs 3.0.14.0 mostly package you will get,

    • Microsoft.Azure.WebJobs.Host 3.0.14.0
    • Microsoft.Azure.WebJobs 3.0.14.0
    • Microsoft.Azure.WebJobs.Extensions.Storage 3.0.10
    • Microsoft.Azure.WebJobs.Extensions 3.0.6
    • Microsoft.Azure.WebJobs.Host.Storage 3.0.14
    • Microsoft.Extensions.Logging.Console 2.2.0

    Here is the Program.cs:

    using Microsoft.Extensions.Hosting;
    using Microsoft.Extensions.Logging;
    
    namespace ConsoleApp9
    {
        class Program
        {
            static void Main(string[] args)
            {
                var builder = new HostBuilder();
                builder.ConfigureWebJobs(b =>
                {
                    b.AddAzureStorageCoreServices();
                    b.AddAzureStorage(a =>
                    {
                        a.MaxDequeueCount = 8;
                        a.BatchSize = 16;
    
                    });
                });
                builder.ConfigureLogging((context, b) =>
                {
                    b.AddConsole();
                });
                var host = builder.Build();
                using (host)
                {
                    host.Run();
                }
            }
        }
    }