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

标签 c# azure azure-webjobs

我不确定是否发生了变化,但我们的 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/

相关文章:

c# - 文件选取器的 Windows 8 手机应用代码错误

azure - 通过查看问题是否来自不受信任的 CA 来检测中间人攻击

security - 在 Windows Azure 中使用 SSL 连接

azure - 导出/导入 Azure API 管理开发人员门户 UI 更改

node.js - 部署后如何重启webjobs?

Azure Web作业授权错误

visual-studio - Azure WebJob - 创建目录失败

c# - 在 C# 中调试 c++ dll

c# - 将 XML 存储在嵌套字典中

c# - 为什么 IEquatable T 没有在 C# 4.0 的 T 中实现逆变?