我在解决方案上升级了一些非常老的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以使其正常工作?
假设您将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
软件包,您将获得此软件包,
这里是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();
}
}
}
}