Using SignalR in Azure Worker Roles
Asked Answered
W

5

12

I have an Azure hosted web application which works alongside a number of instances of a worker role. Currently the web app passes work to these workers by placing messages in an Azure queue for the workers to pick up. The workers pass status and progress messages back by placing messages into a 'feedback' queue. At the moment, in order to inform my browser clients as to progress, I make ajax based periodic polling calls in the browser to an MVC controller method which in turn reads the Azure 'feedback' queue and returns these messages as json back to the browser.

Obviously, SignalR looks like a very attractive alternative to this clumsy polling / queing approach, but I have found very little guidance on how to go about doing this when we are talking about multiple worker roles (as opposed to the web role) needing to send status to individual or all clients .

The SignalR.WindowsAzureServiceBus by Clemens vasters looks superb but leaves one a bit high and dry at the end i.e. a good example solution is lacking.

Added commentary: From my reading so far it seems that no direct communication from worker role (as opposed to web role) to browser client via the SignalR approach is possible. It seems that workers have to communicate with the web role using queues. This in turn forces a polling approach ie the queues must be polled for messages from the worker roles - this polling has to originate (be driven from) from the browser it appears (how can a polling loop be set up in a web role?)

In summary, SignalR, even with the SignalR.WindowsAzureServiceBus scale out approach of Clemens Vasters, cannot handle direct comunication from worker role to browser.

Any comments from the experts would be appreciated.

Warnock answered 4/3, 2012 at 8:26 Comment(2)
What was the most lightweight way you were able to relay worker role => webrole => client browser?Gogh
As bacr have answered. I also have had multiply worker roles running as clients and the webrole controls them.Disclosure
J
6

You can use your worker roles as SignalR clients, so they will send messages to the web role (which is SignalR server) and the web role in turn will forward messages to clients.

Johnnyjohnnycake answered 3/7, 2012 at 14:6 Comment(2)
Do you have an example of how to do this?Incogitant
Down voted this answer because as it currently stands it doesn't add any value.Discommend
U
1

We use Azure Service Bus Queues to send data to our SignalR web roles which then forward on to the clients. The CAT pages have very good examples of how to set up asynchronous loops and sending.

Unreel answered 14/3, 2012 at 13:58 Comment(3)
Thanks @Unreel It seems that the web role has to do the sending to the browser client using SignalR. My problem is that the messages which must be sent originate in worker roles. How to obtain such messages from the worker roles. If they placed these messages in a Service Bus queue it seems the service bus would then need to be polled by the web role. Such polling is what one is trying to avoid by using SignalR in the first place!Warnock
@t0rus: Service Bus queues can be run in blocking mode i.e. no polling. The queue read returns either on a set timeout (eg 24hours) or when a message is received. Blocking an IIS thread on this is a no-no, but with Tasks it would seem the overhead could be low. Wondering if the overhead can be EVEN lower ...Gogh
Looks like the link is down.Incogitant
D
1

Keep in mind my knowledge of this two technologies is very basic, I'm just starting. And I might have misunderstood your question, but it seems pretty obvious to me:

Web roles are capable of subscribing to a queue server where the worker role deposits the message?. If so there would be no client "pulling", the queue service would provide the web server side code with a new message, and through SignalR you would push changes to the client without client requests involved. The communication between web and worker would remain the same (which in my opinion, it's the proper way to do it).

Dual answered 12/7, 2012 at 18:55 Comment(0)
N
1

If you are using the one of the SignalR scaleout backplanes you can get workers talking to connected clients via your web application.

How to publish messages using the SignalR SqlMessageBus explains how to do this.

It also links to a fully worked example which demonstrates one way of doing this.

Nelly answered 23/1, 2014 at 19:36 Comment(0)
S
0

Alternative message bus products such as NServiceBus could be worth investigating. NServiceBus has the ability to deliver messages asynchronously across process boundaries without the need for polling.

Swathe answered 1/11, 2012 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.