Click here to Skip to main content
13,589,923 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


74 bookmarked
Posted 15 Jun 2012
Licenced CPOL

SignalR - Group Notifications

, 15 Jun 2012
Rate this:
Please Sign up or sign in to vote.
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

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

2. Messenger

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:

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

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

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

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:  

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.....

You may also be interested in...

Comments and Discussions

GeneralIssue on IIS Pin
Member 1044509710-May-16 0:44
memberMember 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
memberMember 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-Garrin Balia20-Jun-12 8:31
memberDane-Garrin 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-Garrin Balia20-Jun-12 8:31
memberDane-Garrin 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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.180618.1 | Last Updated 15 Jun 2012
Article Copyright 2012 by Dane Balia
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid