Azure WebJob仅扩展2个工作

时间:2017-07-14 10:10:47

标签: azure azure-webjobs

我在3个实例中运行了一个小型WebJob,WebBob由ServiceBusTrigger触发,每个作业大约需要20秒(我为测试添加了一个睡眠)。

enter image description here

现在我向ServiceBus队列添加了3个项目,但只有2个WebJob实例正在运行。 enter image description here

第三个实例在做什么以及如何让实例也在队列中工作?

我的代码很基本:

    public class Functions
{
    // This function will get triggered/executed when a new message is written 
    // on an Azure Queue called queue.
    public static void ProcessQueueMessage([ServiceBusTrigger("jobs2")] string message, TextWriter log)
    {

        string url = "https://requestb.in/xxxxx";
        log.WriteLine(message);
        log.WriteLine("gotmsg");
        Thread.Sleep(20000);
        log.WriteLine("sending");

        string postData = "test=" + message;

        Console.WriteLine(postData);

        System.Net.WebRequest req = System.Net.WebRequest.Create(url);
        //Add these, as we're doing a POST
        req.ContentType = "application/x-www-form-urlencoded";
        req.Method = "POST";
        //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&
        byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData);
        req.ContentLength = bytes.Length;
        System.IO.Stream os = req.GetRequestStream();
        os.Write(bytes, 0, bytes.Length); //Push it out there
        os.Close();
        System.Net.WebResponse resp = req.GetResponse();
        if (resp == null) return;
        System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
        log.WriteLine(sr.ReadToEnd().Trim());
    }
}

1 个答案:

答案 0 :(得分:1)

  

第三个实例在做什么以及如何让实例也在队列中工作?

第三个实例默认工作。我假设Azure WebApp对多个实例使用指定的LoadBalance策略。似乎我们无法配置LoadBalance策略。在你的情况下,似乎3消息不足以进行测试。请尝试使用更多消息进行测试。我在我身边测试它,它正常工作。以下是发送我使用的消息的测试代码。

QueueClient.CreateFromConnectionString("connection string", QueueName);

 for (int i = 0; i < 20; i++)
 {
     var sendMessage = new BrokeredMessage("test message"+i);
     client.Send(sendMessage);
 }

enter image description here