onefox
onefox

Reputation: 177

Azure WebJob Scale Out only 2 Jobs working

I got a small WebJob running in 3 instances, the WebJob is triggered by ServiceBusTrigger, each job takes about 20 seconds (I added a sleep for testing).

enter image description here

Now i add 3 items to the ServiceBus Queue but only 2 WebJob Instances are working. enter image description here

What is the third instance doing and how can i get the instance to also work on the queue?

My code is very basic:

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

Upvotes: 0

Views: 337

Answers (1)

Tom Sun
Tom Sun

Reputation: 24549

What is the third instance doing and how can i get the instance to also work on the queue?

The third instance shoud work as default. I assume Azure WebApp uses the specified LoadBalance strategy for multiple instances. And it seems that we have no way to config the LoadBalance strategy. In you case it seems that 3 message is not enough for test that. Please have a try to test it with more message. And I test it on my side, it works correctly. The following is the test code for sending message I used.

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

Upvotes: 1

Related Questions