Search code examples
asp.net-mvcwcfazureazure-worker-rolesazure-web-roles

Best way to comunicate between ASP.NET app and Worker Role


I have both ASP.NET app and Worker Role set up and now I wonder how do I communicate between them? I think that the idea is that the solution will be distributed across different geographic locations. So how do I link the distributed Worker and Web Roles in a simple and efficient way? I have started to look into WCF, but it looks to me to be an overkill and overcomplicated. Another thought I had is to use SignalR client inside the Worker roles to talk with the server in the Web roles.

EDIT:

The exact context:

1)User uploads file to the server

2)Server sends file to Azure Storage and adds the file name to CloudQueue

3)Worker gets the file name from CloudQueue

4)Worker starts a new Thread that gets the file from Azure Storage and starts processing it

5)Worker/Thread reports back to the application at every step of the file processing

6)The application receives the reports and uses SignalR to forward the processing steps to the client's browser in real time.

What I am missing is at steps 2 > 3, How to immediately notify the Worker that a new file has arrived? I don't want to poll the CloudQueue because it will create delays. Also at steps 5 > 6, Worker needs to notify the application about the steps and this should be without delay, but again I don't see how a polling solution can be used in such case.


Solution

  • AS stated above, a little bit more context is needed. You basically have two main options, Windows Azure Queues and Windows Azure Service Bus Queues/Topics. My personal advice would be to use Azure Queues if the Web and Worker Roles are colocated in the same region and Service Bus Queues if they are not. I would have to ask why are you not colocating your Web and Worker Roles together, if you have a geographic deployment of you app then look at deploying all your Web Roles and Work Roles in each Region e.g. US, Europe & Asia and then use Traffic Manager to route user to the optimal region.

    There is a good blog post on when to use which queue 'Windows Azure Queues and Windows Azure Service Bus Queues - Compared and Contrasted': http://msdn.microsoft.com/en-us/library/windowsazure/hh767287.aspx

    HTH

    EDIT

    A good approach for Web and Worker Role communication is below (I stole this from a recent thread which @smarx answered)

    1 Web role writes a message to the queue that includes a job ID.

    2 Worker role does the work and writes the result to a table with partition key .

    3 Web role is polling that row of the table. Once it exists, the answer comes back.

    In your case you could have the Worker Role update the Table Storage with the status updates and then have your Web Role pick them up and display them to the user. e.g. 20%, 50%, Complete etc...

    I don't really see delays in this type of communication, as long as you are polling sufficiently from the Web Role (*note transactions costs)

    I presume some sort of Inter Role communication could be done here for status updates but it might be overkill IMO:

    http://msdn.microsoft.com/en-us/library/windowsazure/hh180158.aspx