Azure WebJobs:不推荐使用Microsoft.Tpl.Dataflow

问题描述 投票:0回答:1

我在解决方案上升级了一些非常老的nuget程序包,发现在用于Azure Webjob的控制台应用程序中,Microsoft.Tpl.Dataflow程序包(我使用的是v4.5.24)已弃用。因此,我不得不使用Nuget替代品:System.Threading.Tasks.Dataflow,v4.11.0。

这里是我的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();
    }
}
  • new JobHostConfiguration()现在不见了
  • [new JobHost()现在需要两个参数
  • host.RunAndBlock()不见了

另一个问题是QueueTrigger也没有找到,但是有一个单独的软件包帮助了Microsoft.Azure.WebJobs.Extensions.Storage, v3.0.10

这是一个经典的.Net 4.7.2类库项目。我正在查看有关“ new JobHost()”的两个参数的文档,并且我感觉到.Net Core。我现在陷入僵局了吗?如何转换Program.cs以使其正常工作?

c# azure-webjobs .net-4.7.2
1个回答
0
投票

假设您将Web作业包从v1升级到v3,大部分配置可以参考官方教程:Get started with the Azure WebJobs SDK for event-driven background processing

关于队列触发Webjob,您必须显式安装存储绑定扩展的v3 webjob,更多详细信息,请参见此处:Install the Storage binding extension

然后是有关队列触发器Webjob配置的信息,如果要设置批处理大小.etc,则可以参考:Queue storage trigger configuration。通常,您的问题可以从教程或其他文档中获得答案。

下面是我关于网络472网络作业的示例代码。

这是我的webjob软件包和版本。使用v3 webjob时,依赖项具有System.Threading.Tasks.Dataflow (>= 4.8.0),因此主要安装Microsoft.Azure.WebJobs 3.0.14.0软件包,您将获得此软件包,

  • 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

这里是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();
            }

    }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.