Click here to Skip to main content
11,411,922 members (66,835 online)
Click here to Skip to main content

Tagged as

SignalR - Group Notifications

, 15 Jun 2012 CPOL
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.....
Follow on   Twitter   Google+

Comments and Discussions

QuestionWorking Version (including Cross Domain) with Latest SignalR (jquery.signalR-1.1.0 and Owin) [modified] PinmemberCurtis Shull19-May-13 4:34 
QuestionCross Domain PinmemberCurtis Shull14-May-13 11:39 
QuestionNot working PinmemberMember 1002026730-Apr-13 7:07 
QuestionCan not make it running Pinmembermanfbraun4-Mar-13 11:48 
AnswerRe: Can not make it running PinmemberMember 1002026730-Apr-13 6:55 
GeneralRe: Can not make it running Pinmembermanfbraun30-Apr-13 10:07 
GeneralRe: Can not make it running PinmemberDane Balia30-Apr-13 21:06 
QuestionTrying to get it to send via the same page within the same host Pinmemberdanlegion4-Nov-12 16:42 
AnswerRe: Trying to get it to send via the same page within the same host PinmemberDane Balia4-Nov-12 21:05 
QuestionIs it possible to implement it in windows app PinmemberValdet Zabeli29-Oct-12 5:42 
Bugissues running under iis7 Pinmembersacon22-Oct-12 3:49 
GeneralRe: issues running under iis7 PinmemberDane Balia22-Oct-12 22:34 
GeneralRe: issues running under iis7 PinmemberIlya Builuk24-Oct-12 5:40 
QuestionCan I use this code PinmemberMember 231147019-Oct-12 11:58 
GeneralRe: Can I use this code PinmemberDane Balia21-Oct-12 19:52 
QuestionGreat example PinmemberMember 231147019-Oct-12 11:46 
QuestionSignalr whether to support the load balance PinmemberMember 780670426-Aug-12 18:56 
QuestionCan't download source Pinmembermontyno520-Jun-12 5:32 
AnswerRe: Can't download source PinmemberDane-Garrin Balia20-Jun-12 9:31 
GeneralNice Colors! PinmemberSound Logic20-Jun-12 2:04 
GeneralRe: Nice Colors! PinmemberDane-Garrin Balia20-Jun-12 9:31 
GeneralMy vote of 5 Pinmemberninoslav.pejic18-Jun-12 23:46 
GeneralMy vote of 3 PinmemberVitaly Tomilov15-Jun-12 8:41 
GeneralRe: My vote of 3 Pinmemberandrusha00715-Jun-12 12:11 
GeneralRe: My vote of 3 PinmemberVitaly Tomilov15-Jun-12 14:57 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.5 | Last Updated 15 Jun 2012
Article Copyright 2012 by Dane Balia
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid