SignalR push notifications

envo

Expert Member
Joined
Jan 14, 2014
Messages
3,265
Reaction score
437
Hi guys, was wondering if I can pick some brains.

There's tons of tutorials on how to implement "push notifications" on your web application using SignalR, but most/if not all requires some action to happen manually (like a controller being invoked by a user and/or a button click)

We have a list of records that needs to be printed, I need to show the number of records if any is available to the user. Once they print it, a print flag is set, making the number available to print, 0. This is specific to a user.

I've found a tutorial that uses sql broker and sqldependancy to notify when database changes occur, but that's not really what I am looking for.

Currently we're using the old way of setTimeout to poll the server constantly for any changes. I'm (obviously) trying to reverse that, saying that if there's any records TO print for a specific user, only notify them then.

Do you guys have any ideas on how I would implement something like that? Basically, when a client opens the website and logs in, they "subscribe" to the push notifications using their user ID. The server needs to somehow broadcast to that specific user ID that they have x number of records available to print.

I'm basically stuck at "how does the server send that push notifications without some kind of page reload or button being clicked"

Thanks :)
 
what we did is write a windows service that wakes up every minute. it then checks whatever and if needed makes an http web request to a certain url.

the controller then invokes signalr and sends a message client side.

also you can use something like msmq with masstransit to send messages from a web service to a website if they are on the same machine...
 
what we did is write a windows service that wakes up every minute. it then checks whatever and if needed makes an http web request to a certain url.

the controller then invokes signalr and sends a message client side.

also you can use something like msmq with masstransit to send messages from a web service to a website if they are on the same machine...

Thanks for the tips. I did write a windows service the other day that will dynamically load and call functions (sort of a pluggable service thing) so you can easily implement stuff like that. Might as well finalize and launch that windows service so it's easy to just throw in a DLL that will run every x minutes. Will also look into msmq with mass transit since we're already running msmq for some of our integration
 
I also almost went down the sql broker route. Ended up creating a timer to check for certain changes every second or so.

But I much prefer the Windows service route. However, I think the right way of doing it is to use msmq...
 
SignalR is a tad buggy, but what you can do is have a timer/quartz task running pushing to a concurrent list of connected users, store the connectionid and push to those specific id's or you can register users to groups.

You do not need to invoke a controller to make a push from signalr, just use a self hosted container of it.
 
what we did is write a windows service that wakes up every minute. it then checks whatever and if needed makes an http web request to a certain url.

the controller then invokes signalr and sends a message client side.

also you can use something like msmq with masstransit to send messages from a web service to a website if they are on the same machine...

That is so inefficient, unless you are hosting hub proxies within the web application itself its a different story, but with a self hosted signalr server you need not post to controllers to post/invoke messages.
 
Hi guys, was wondering if I can pick some brains.

There's tons of tutorials on how to implement "push notifications" on your web application using SignalR, but most/if not all requires some action to happen manually (like a controller being invoked by a user and/or a button click)

We have a list of records that needs to be printed, I need to show the number of records if any is available to the user. Once they print it, a print flag is set, making the number available to print, 0. This is specific to a user.

I've found a tutorial that uses sql broker and sqldependancy to notify when database changes occur, but that's not really what I am looking for.

Currently we're using the old way of setTimeout to poll the server constantly for any changes. I'm (obviously) trying to reverse that, saying that if there's any records TO print for a specific user, only notify them then.

Do you guys have any ideas on how I would implement something like that? Basically, when a client opens the website and logs in, they "subscribe" to the push notifications using their user ID. The server needs to somehow broadcast to that specific user ID that they have x number of records available to print.

I'm basically stuck at "how does the server send that push notifications without some kind of page reload or button being clicked"

Thanks :)

We have over 1,000 people currently subscribing to various channels on our web platform, the socket connects to our backend, the backend queries redis and returns the cache when the elapsed time has passed redis is updated from the various tasks. We did it this way to reduce the amount of database hits. We have some users who are constantly hitting "refresh", so this way we alleviate that crap.
 
I agree with the windows service idea. At least you are solving the issue with 1000 connections polling your servers for updates. Single service polling the database for changes and informing all clients of that change.

Then there is always the dodgyness of sql CLR's. Creating a clr to push notifications to your server and pushing it out to the clients will be quite straight forward, but not to sure if I would go this route.
 
Nope i would never use sql CLR, but in our case our DB is postgres anyways, we do a lot of async rabbitmq transactions between services which also reduces db load.
 
here we go again.
please tell me the optimal solution to a vaguely described problem in a system you've never seen and an environment you've never experienced
semaphore reminds me of AcidRazor some times.
 
There are always multiple optimal solutions to a problem. Describe the issue you had or what the system does and I'm pretty sure there will be multiple efficient options given.

Timers triggering a controller triggering signal-r just sounds hellish inefficient to me. But then hosting hubs within a mvc app in my opinion is bad design. There is much more flexibility when self hosted, but if you're using hubs to connect to other parts of the site almost like broadcast events then that's when i would only go that route, but then i would just use an event aggregator instead of signalr.


@Fuma - Thanks :D He is my hero :erm:
 
Last edited:
lol

I'm going for the self-hosted solution in a Windows Service. If it's done correctly, I can spin off more hubs for other notifications that need to go through and I don't have to rely on a website being live/controller being executed.

I was looking for ideas, not specific solutions and being vague-ish means I get a wide range of ideas that I can go through and see which best fits and where I want to go in future and how it will fit in there. :)
 
Top
Sign up to the MyBroadband newsletter
X