简体   繁体   中英

Azure WebJobs QueueTrigger not triggering

I'm trying to find what I'm doing wrong regarding an Azure WebJobs QueueTrigger method that should be triggered from an Azure Storage Queue.

I've read a couple of documents (as in blog posts / msdn articles). But I'm still not clear.

Main question / misunderstood aspect:

What should be the name of the connection string for Azure storage console app App.config or Windows Azure Configuration (portal). So far I have the following name set at both places.

  • AzureJobsStorage
  • AzureWebJobsStorage
  • AzureJobsRuntime
  • AzureJobsDashboard
  • AzureJobsData

Here's my WebJobs console app code.

static void Main()
{
    JobHost host = new JobHost();
    host.RunAndBlock();
}

public static void CreateLeague([QueueTrigger("temp")] string msg)
{
    var task = JsonConvert.DeserializeObject<QueueTask>(msg);

    if (task.TaskType == QueueTask.TaskTypes.Pdf)
      RenderPdf(task.Id);
}

This console app is continuously running on my Azure Website.

I can access its "debug" page where I can toggle output and I see it is started / running.

My code to add queue (from my ASP.NET MVC app):

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("temp");
queue.CreateIfNotExists();
Common.QueueTask task = new Common.QueueTask();
task.TaskType = Common.QueueTask.TaskTypes.Pdf;
task.Id = p.Id;
CloudQueueMessage msg = new CloudQueueMessage(JsonConvert.SerializeObject(task)      );
queue.AddMessage(msg);

This code is executed, and queue are added to my Storage Account. But they did not get "dequeue" or read from the WebJobs.

Hmm, the WebJobs class had to be public.

using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
using Proceed.Common;
using System;
using System.Configuration;
using System.IO;

public class WebJobsTask {
  public static void Main()
  {
      JobHost host = new JobHost();
      host.RunAndBlock();
  }

  public static void CreateLeague([QueueTrigger("temp")] string msg)
  {
    var task = JsonConvert.DeserializeObject<QueueTask>(msg);

    if (task.TaskType == QueueTask.TaskTypes.Pdf)
      RenderPdf(task.Id);
  }
}

Also found a quick way to explore my queues: https://azurestorageexplorer.codeplex.com/ .

在我的例子中,我假设QueueTrigger指的是服务总线队列而不是Azure队列 ,我实际上需要使用ServiceBusTrigger

  1. You can use the server explorer in VS to explore the content of the Storage queues.
  2. The queue triggers for the WebJobs SDK will exponentially back off if there is no work to do. There might be a delay between the moment a message is put in a queue and the moment when it is picked up. You can configure the maximum back off through the JobHostConfiguration.Queues.MaxPollingInterval property.
  3. For the latest SDK you need two storage connection strings AzureWebJobsStorage and AzureWebJobsDashboard

This is a great place for more resources: https://docs.microsoft.com/en-us/azure/app-service-web/websites-webjobs-resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM