Azure Webjobs和Servicebus触发器 - 在nuget包升级后无法找到功能

时间:2015-10-01 18:59:15

标签: c# azure azure-webjobs

我不确定某些内容是否已更改,但我们的Windows Azure webjob JobHost不再看到Functions.cs文件中包含的功能。我们刚刚在此解决方案上升级了Azure Nuget软件包(不确定是否相关)。

Program.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";
        }
    }

Function.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();
            }
        }

    }


}

结果 http://imgur.com/QvJ2Ca5

我一直在搜索并找到与确保函数类是公共静态相关的答案,但不是更多。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:5)

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

我们这样做是为了将ServiceBus与核心WebHobs SDK库分离,我们还将其移到了新的可扩展性模型上。

请将该行添加到您的启动代码中,您应该很好。