Click here to Skip to main content
14,836,067 members
Articles / Programming Languages / C#
Posted 15 Jun 2012

Tagged as


75 bookmarked

SignalR - Group Notifications

Rate me:
Please Sign up or sign in to vote.
4.60/5 (22 votes)
15 Jun 2012CPOL3 min read
A Sample Broadcast Notification System with Groups from an External Application


The aim of what we will be trying to accomplish in this tutorial is to create a sample Broadcast Notification System using SignalR where specific groups can receive "notifications" in real time, from an external application.


A Real World Application: A perfect case for this would be a single source of code that services multiple customers or domains. Example;{username}, and based on the parameter username, the site is customized to include the content of that user. Single code source, but multi-domain.

Aim Simply to notify (send messages), based on a Group or Unique Identifier. Secondly to do this using an external application, that way a separate Windows Service (for example) can be created to broadcast messages to Groups. 

Design: A simple messaging architecture based on three classes;

  1. Message - a basic unit
  2. Messenger -  a manager of Messages (actions to take on messages) 
  3. MessengerHub - the interface for SignalR 

Using the code  

(A) The Server-Side

First design the basic types that will be used on the Server-Side. When I say Server-side, I mean in this case the actual WebSite/Web Application or Project. In this sample code, I will be using a WebSite Project in Visual Studio 2010.

1. Message

Image 1

Quite simply the container or basic data unit that represents an actual Message  

2. Messenger

Image 2

In the Messenger class we have a created an Instance manager which will be dynamically generated on Request (using the type Lazy) 

Secondly a GetAllMessages will be used for getting all the messages that is contained in the ConcurrentDictionary. You can better filter this for support for your groups etc.

Thirdly, a BroadCast to a specific group which will the foundation of all our Messenger's (so to speak); where it will get all clients by a specific group.

Here is the GetClients method:

Image 3

This will basically find our MessengerHub, and return a set of clients that belong to the specified group. Then using the BroadCast message above, using the "add" method to send a notification to each one of the Clients in that group. 

3. MessengerHub

Image 4

We create an AddToGroup, GetAllMessages, BroadCastMessage to our class which will be our implementation of Messengers, but will also be the exposed interfaces for our remote application to call, when it connects to x.x.x.x/signalr/hubs. 

(B) Client-Side Script

Image 5

This client side will basically the "start" of all things SignalR. Please note in the WebSite Project I have created, the previous three classes were added into "App_Code".

The above is quite simplistic. jGrowl is being used for the notification system or pop-up that will appear in browser.

The group that I am using ("sourcing") can be custom to whatever suits you (customer name, hostname etc). 

(C) The External-Application

Image 6

The Console Application above is basically the external application and the method by which SignalR is remotely called. Basically it creates a Proxy which communicates to the remote site.  

The result:  

Image 7

Points of Interest 

In my case above; http://localhost:9616/signalr. It's also a great test to check if your SignalR is working on the Server-Side; http://localhost:9616/signalr/hubs. You should see an extension, with all your "methods" you exposed. 

Both samples are included and should get you started.  


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dane Balia
Software Developer (Senior) Senwes
South Africa South Africa
Hacking at code.....

Comments and Discussions

GeneralIssue on IIS Pin
Member 1044509710-May-16 0:44
professionalMember 1044509710-May-16 0:44 
GeneralRe: Issue on IIS Pin
Dane Balia10-May-16 1:31
MemberDane Balia10-May-16 1:31 
GeneralRe: Issue on IIS Pin
Member 1044509710-May-16 1:43
professionalMember 1044509710-May-16 1:43 
QuestionWorking Version (including Cross Domain) with Latest SignalR (jquery.signalR-1.1.0 and Owin) Pin
Curtis Shull19-May-13 3:34
MemberCurtis Shull19-May-13 3:34 
QuestionCross Domain Pin
Curtis Shull14-May-13 10:39
MemberCurtis Shull14-May-13 10:39 
QuestionNot working Pin
Member 1002026730-Apr-13 6:07
MemberMember 1002026730-Apr-13 6:07 
QuestionCan not make it running Pin
manfbraun4-Mar-13 10:48
Membermanfbraun4-Mar-13 10:48 
AnswerRe: Can not make it running Pin
Member 1002026730-Apr-13 5:55
MemberMember 1002026730-Apr-13 5:55 
GeneralRe: Can not make it running Pin
manfbraun30-Apr-13 9:07
Membermanfbraun30-Apr-13 9:07 
GeneralRe: Can not make it running Pin
Dane Balia30-Apr-13 20:06
MemberDane Balia30-Apr-13 20:06 
QuestionTrying to get it to send via the same page within the same host Pin
danlegion4-Nov-12 15:42
Memberdanlegion4-Nov-12 15:42 
AnswerRe: Trying to get it to send via the same page within the same host Pin
Dane Balia4-Nov-12 20:05
MemberDane Balia4-Nov-12 20:05 
QuestionIs it possible to implement it in windows app Pin
Valdet Zabeli29-Oct-12 4:42
MemberValdet Zabeli29-Oct-12 4:42 
Bugissues running under iis7 Pin
sacon22-Oct-12 2:49
Membersacon22-Oct-12 2:49 
GeneralRe: issues running under iis7 Pin
Dane Balia22-Oct-12 21:34
MemberDane Balia22-Oct-12 21:34 
GeneralRe: issues running under iis7 Pin
Ilya Builuk24-Oct-12 4:40
MemberIlya Builuk24-Oct-12 4:40 
QuestionCan I use this code Pin
Member 231147019-Oct-12 10:58
MemberMember 231147019-Oct-12 10:58 
GeneralRe: Can I use this code Pin
Dane Balia21-Oct-12 18:52
MemberDane Balia21-Oct-12 18:52 
QuestionGreat example Pin
Member 231147019-Oct-12 10:46
MemberMember 231147019-Oct-12 10:46 
QuestionSignalr whether to support the load balance Pin
Member 780670426-Aug-12 17:56
MemberMember 780670426-Aug-12 17:56 
QuestionCan't download source Pin
montyno520-Jun-12 4:32
Membermontyno520-Jun-12 4:32 
AnswerRe: Can't download source Pin
Dane Balia20-Jun-12 8:31
MemberDane Balia20-Jun-12 8:31 
GeneralNice Colors! Pin
Sound Logic20-Jun-12 1:04
MemberSound Logic20-Jun-12 1:04 
GeneralRe: Nice Colors! Pin
Dane Balia20-Jun-12 8:31
MemberDane Balia20-Jun-12 8:31 
GeneralMy vote of 5 Pin
ninoslav.pejic18-Jun-12 22:46
Memberninoslav.pejic18-Jun-12 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.