The Link Between WebJob and SignalR Hub

I have the following script:

  • I have an azure webjob (used to send emails) and I need to check the progress of the webjob in my web application.
  • I use SignalR to communicate with clients from my server.
  • When I want to send an email, I click on the message in the queue and the azure webjob does its job.

The question is, how can I report the progress of the webjob to the client? My initial idea was to pull a message from a webjob, so the hub could read it from the queue. Then I will notify clients from the center. However, I can’t find a way to tell the website and the hub, I don’t know how to trigger an action in the hub when the message is placed in the queue or on the service bus. That is, I do not know how to sign a hub to a specific queue message.

Can someone help me?

+8
asp.net-mvc-5 signalr azure-webjobs azure-webjobssdk azure-servicebus-queues
source share
1 answer

The way I did this is to configure the web application as a SignalR client, route messages through SignalR from the website to the server, and then send these messages to SignalR web clients.

Start by installing the SignalR Web Client (nuget's package identifier is Microsoft.AspNet.SignalR.Client) on the website.

Then in your web project, initialize the SignalR connection concentrator and send messages to the server, for example:

public class Functions { HubConnection _hub = new HubConnection("http://your.signalr.server"); var _proxy = hub.CreateHubProxy("EmailHub"); public async Task ProcessQueueMessageAsync([QueueTrigger("queue")] EmailDto message) { if (_hub.State == ConnectionState.Disconnected) { await _hub.Start(); } ... await _proxy.Invoke("SendEmailProgress", message.Id, "complete"); } } 

Your SignalR server will receive these messages and then be able to send them to other SignalR clients, for example:

 public class EmailHub : Hub { public void SendEmailProgress(int messageId, string status) { Clients.All.broadcastEmailStatus(messageId, status); } } 
+9
source share

All Articles