Hi I am building a Cloud Service which has (for the moment) one web and one worker role. My desired workflow would be: the browser calls a webApi controller on the web role, which sends a message to a queue (or service bus) which is then processed by the worker role. So far so good. Now when the worker role finishes processing the message I would like to call a method on the web role, who will then signal the browser that the processing has completed (via SignalR). Please excuse me if this is not the right place to ask since this is more like a “best practice” question rather that a real problem. I have so far considered 2 approaches:
The worker role updates a table row (in the table storage) with the progress and the completion of the task. There is no signaling to the web role. The browser reads polls the table storage directly (via REST api) and therefore knows when the task has completed. This works well (I have already tested it), even though I don’t like the approach of constant polling and I would like to have an “event-based” solution. Moreover, once the client gets the info that the process has finished, it must perform an additional call to a web api method to broadcast to the other clients (via SignalR) that the operation was completed.
Using Interrole communication together with SignalR (see code sample below) also works (already tested as well)
Code sample:
var protocol = "http";
var ipAddress = RoleEnvironment.Roles["XXX.YYY.Web"]
.Instances[0]
.InstanceEndpoints.ToArray()
.Where(ep => ep.Value.Protocol == protocol)
.First()
.Value.IPEndpoint.ToString();
var stringEndpoint = string.Format("{0}://{1}", protocol, ipAddress.ToString());
Trace.WriteLine("Retrieved endpoint address: " + stringEndpoint, "Information");
HubConnection connection = new HubConnection(stringEndpoint);
IHubProxy proxy = connection.CreateHubProxy("MyWebHub");
connection.Start().Wait();
//later...
proxy.Invoke("ProgressUpdated", clientId, progress);
My question is: are there other (better) ways to communicate in direction Worker role -> Web role? That is, trigger a method on the web role when a worker role has finished its processing? The method on the web role would then broadcast the update to all clients via SignalR. I have also taken a look at Event Hubs but to my understanding the Event Consumers would still run on the worker role.