gpt4 book ai didi

c# - Azure Webjobs 和 Servicebus 触发器 - nuget 包升级后找不到函数

转载 作者:行者123 更新时间:2023-12-03 04:47:02 25 4
gpt4 key购买 nike

我不确定是否发生了变化,但我们的 Windows Azure webjob JobHost 不再看到 Functions.cs 文件中包含的函数。我们最近刚刚升级了此解决方案上的 Azure Nuget 包(不确定是否相关)。

程序.cs

using M5Worker.Classes;
using Microsoft.Azure.WebJobs;
using Microsoft.ServiceBus.Messaging;
using System;
using TuesPechkin;

namespace M5Worker
{
// To learn more about Microsoft Azure WebJobs SDK, please see http://go.microsoft.com/fwlink/?LinkID=320976
public class Program
{
// This is needed for pechkin do not remove!
public static readonly IConverter converter =
new ThreadSafeConverter(
new PdfToolset(
new Win64EmbeddedDeployment(
new TempFolderDeployment())));

//published with devmode false
public static bool DevMode = false;
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
public static void Main()
{
libUFE.clsLogging cLog = new libUFE.clsLogging("M5");
try
{
cLog.LogWrite(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, "", "", "Information", "M5Worker has Started", 0, "");

JobHostConfiguration jhc = new JobHostConfiguration();

if (DevMode == false)
{
jhc.ServiceBusConnectionString = Properties.Settings.Default.strSBConnProd;
}
else
{
jhc.ServiceBusConnectionString = Properties.Settings.Default.strSBConnDev;
}
jhc.DashboardConnectionString = "##################";
jhc.StorageConnectionString = "##################";
jhc.Queues.MaxPollingInterval = TimeSpan.FromSeconds(30);
jhc.NameResolver = new QueueNameResolver();

JobHost jh = new JobHost(jhc);
jh.RunAndBlock();

cLog.LogWrite(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, "", "", "Information", "M5Worker has Finished", 0, "");
}
catch (Exception ex)
{
cLog.LogWrite(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, "", "", "Error", ex.Message, 0, "");
cLog.LogWrite(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, "", "", "Information", "M5Worker has Finished", 0, "");
}
}

public class QueueNameResolver : INameResolver
{
public string Resolve(string name)
{
if (DevMode == true)
return "m5queuedev";
else
return "m5queue";
}
}

函数.cs

using Microsoft.ApplicationServer.Caching;
using Microsoft.Azure.WebJobs;
using Microsoft.ServiceBus.Messaging;
using Newtonsoft.Json;
using System;
using M5Worker.DB;
using System.Threading;
using System.Data;
using M5Worker.Classes;

namespace M5Worker
{

public class Functions
{

public static libUFE.clsLogging cLog = new libUFE.clsLogging("M5");

// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void M5Worker([ServiceBusTrigger("%queuename%")] BrokeredMessage message)
{
if (message != null)
{
try
{

if (message.Properties.Count > 0 && message.Properties.ContainsKey("Function"))
{
//message.Complete();
switch (message.Properties["Function"].ToString().ToUpper())
{
case "CREATEELECTRONICFORECLOSURE":
FunctionHandler.ProcessMessage(message, clsElectronicForeclosure.processItem, true);
break;

case "PROCESSCUSTOMER":
FunctionHandler.ProcessMessage(message, clsProcessCustomer.ProcessCustomerObject, true);
break;
}
}
else
{
throw new Exception("Message does not contain function");
}
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
cLog.LogWrite(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, "", "", "Error", ex.Message, 0, "");
// Indicate a problem, unlock message in queue
message.DeadLetter();
}


message.Dispose();
}
}

}


}

结果为 /image/0ocZ5.jpg

我一直在四处搜索,找到了与确保函数类是公共(public)静态相关的答案,但仅此而已。

如有任何帮助,我们将不胜感激。

最佳答案

您现在必须在启动代码“config.UseServiceBus()”中添加一行以注册 ServiceBus 支持。请参阅此处的示例:http://github.com/Azure/azure-webjobs-sdk-samples/blob/master/BasicSamples/ServiceBus/Program.cs#L26

我们这样做是为了将 ServiceBus 与核心 WebHobs SDK 库解耦,并且我们还将其转移到新的可扩展性模型中。

请将该行添加到您的启动代码中,这样就可以了。

关于c# - Azure Webjobs 和 Servicebus 触发器 - nuget 包升级后找不到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32894899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com