Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send notification to web client from external service via SignalR hub hosted in Asp.Net MVC Application

Scenario is as follow : We have a Asp.Net MVC 4 App having a private messaging system that hosts a signalR hub used to notify users when new message are available for them. Everything works fine, the Web App register connectionId along with their username and the signal is sent to the hub from the DataLayer via a notificationAdapter class.

The problem came when we had to create a separate service leveraging Quartz.Net that also send private messages when tasks are finished. We want the Quartz service to be able to contact the Hub but we can't cause it is in a separate process. I don't want to use the signalR .net client because I don't need a permanent connection between the Quartz based service and my Web App. I think of creating an endpoint in my WebSite to expose Hub's server method to the service or to use ScaleOut for that but I feel like I miss something and though I would ask the community.

like image 804
VdesmedT Avatar asked Oct 02 '13 12:10

VdesmedT


People also ask

How do I send client specific messages using SignalR?

We change the BroadcastChartData() method to accept connectionId as an additional parameter. This way, we can find the client using the connectionId and send a message just to that client. Additionally, we add a new GetConnectionId() method, which returns the connectionId of the client.

How do you send a notification in SignalR?

You can code a SignalR hub and configure a communication endpoint to connect with your apps using client libraries. First, create a hub or class for persistent connections (invocation model) between server and client. Then, create a subscription to the hub method and a code to invoke a hub method to send messages.

Can SignalR be used in Web API?

SignalR can be used together with Web API just fine, so some functionality in application which is not realtime and doesn't require persistent connection could be served by Web API.


2 Answers

This might be a very late answer but seeing as there were no actual accepted answer. I'll provide one.

The easiest way to have your Quartz.NET application send information to your ASP.NET Web Application without implementing a heavy solution such as Enterprise Service Bus (ESB) is to simply expose a web service in ASP.NET and have your Quartz.NET call the ASP.NET web service when its task is finished. Once you're in your ASP.NET web service you should be able to a notification back to send a notification to the client through signalR.

like image 147
TchiYuan Avatar answered Sep 21 '22 00:09

TchiYuan


I would have used Quartz Listener (Job or trigger listener) in the WebAPI, which then talks to the Hub.

Of course, use a shared ADO store between Quartz client (web API) and server (windows service).

like image 29
Yasin75 Avatar answered Sep 19 '22 00:09

Yasin75