Using the Webjobs SDK in a Web Role

We have an Azure web role that needs to monitor the Service Bus queue to respond to earlier requests (which will then be passed to the client via SignalR).

We first wanted to use the message pump (QueueClient.OnMessage) in WebRole.OnStart (). However, we have grown to be very similar to the WebJobs SDK, especially in the way it frees the programmer from any lower level implementation and toolbar.

For various reasons, we want to keep the Web role rather than switch to WebSite. So the question is, How do I use the WebJobs SDK in the Azure Web role? In a little experiment, we adapted the Web OnStart () function in WebRole.cs as follows:

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        JobHostConfiguration config = new JobHostConfiguration()
        {
            ServiceBusConnectionString = "...", 
            StorageConnectionString = "...",
            DashboardConnectionString = "..."
        };

        JobHost host = new JobHost(config);
        host.RunAndBlock();

        return base.OnStart();
    }

    public static void ProcessQueueMessage([ServiceBusTrigger("MyQueue")] string inputText)
    {
        Trace.WriteLine(inputText);
    }
}

      

Everything seems to be working fine, but it is difficult for us to assess the impact it has on the role of the Internet. Are there any consequences? Perhaps scaling the role of the Web?

Thank.

+3


source to share


1 answer


The WebJobs SDK should work fine in WebRole.

I have one suggestion for your implementation: don't block the method OnStart

. RunAndBlock

Use Start

/ instead of calling StartAsync

. This will not block this method and will create a separate thread for the job host.

It might look like (not sure if it compiles):



public class WebRole : RoleEntryPoint
{
   private JobHost host;

   public override bool OnStart()
   {
       JobHostConfiguration config = new JobHostConfiguration()
       {
           ServiceBusConnectionString = "...", 
           StorageConnectionString = "...",
           DashboardConnectionString = "..."
       };

       host = new JobHost(config);
       host.Start();

       return base.OnStart();
   }

   // Not sure if this is the signature of OnStop
   // or even if this method is called this way
   public override bool OnStop()
   {
       host.Stop();
       return base.OnStop();   
   }

   public static void ProcessQueueMessage([ServiceBusTrigger("MyQueue")] string inputText)
   {
       Trace.WriteLine(inputText);
   }

      

}

+3


source







All Articles