Refering to documentation (https://docs.wisej.com/docs/concepts/background-tasks) what is the best way to send different notifications to different clients ? Eg. I want to only send/update stock price updates to the clients which display these stocks. Or for a chat application only send notification to the clients based on the chat rooms they are in …
thank you so much for your sample ! I’ll have a detailed look at it…
At the moment I’m at a customers site and I noticed a strange behavior which does not occur on my laptop (other internet access !). Maybe the network is locked down but I have no idea what this could cause:
The stock quotes are not updated automatically. They only get updated when I do a click on the page. In addition the session timeout dialog does not count down. It displays the minutes left and thats it…
Do you have any idea what can prevent the events to arrive ? I’m sure websocket connections of other application do work but I also know these are HTTPS connections…
I have attached a different example. You can have as many clients as you like and subscribe to any number of stocks. Each client will only update the stocks it’s interested about. The server doesn’t care about the specific stocks, it sends the list of changes to all the listeners without transferring anything. Only the changes make it to the browser.
Each client animates the last update and animates the quote that has been updated.
[Edited] You can also try it here: http://demo.wisej.com/stockquotes
I’d suggest a different approach. Each client knows what it wants to read and display. The background task knows when a quote has changed. This is a typical subscriber/listener event pattern. The server exposes an event, say “QuotesUpdated”, and exposes a method or property to retrieve the quote for a particular stock. The background task checks whatever it needs to check at regular intervals, or receives updates in other ways, it doesn’t really matter how.
When the server process decides to inform the clients that something has changed it fires a single event “QuotesUpdated”. The server’s job is done. It doesn’t matter how many clients have subscribed and are listening. The event may even carry the list of stocks that have changed. The size doesn’t matter at all since it’s not transferred anywhere.
Each client will receive the event, and since each client knows which stocks it needs to update then it can use the sender instance, which is a reference to the server instance, to retrieve the particular quotes and updates the UI if necessary. Each client will only update for the stocks it’s interested to. This can be done synchronously or asynchronously.
thanks for your answer but I’m not sure if one of your solutions would fulfill my needs. When I think about of 100+ different stock quotes one event for each doesn’t make much sense in my opinion. In addition the amount can vary…
Your second solution I think would not be possible because of the much amount of data which is transfered to the client beacuse this should be also used on smartphones/tablets…
Let me describe what I have in mind: E.g. each client sends the data to subscribe (e.g. stock numbers) to the server. The server maintains a list of the clients subscription data as well as their session-id (or something like this). Once a stock quote updates the server side application loops through this list and notifies all clients/sessions which have this stock subscribed with an event…
But I don’t know if this would be possible. I think this would require WiseJ to be able to fire event for particular sessions…
I have put together a simple sample that (hopefully) illustrates what is described in our documentation.
The idea behind this sample is a background text that fires events. In our case it fires the first event every 10 seconds,
i.e. when the seconds part of the current datetime is 0,10,20,30,40,50. The second event is fired every 5 seconds.
This is just for simplification and could be triggered by any other event that happens in the background.
On the user interface you can now subscribe to this event and then a simple counter is increased:
So the idea is here to raise different events. You could also have a single event with all relevant data (e.g. stock quotes) and decide on the content what to update. But I think you get the idea behind this.
When I now open several browser sessions (with ?sid=new), you can see that they all can subscribe individually:
I will describe the code more detailed in a future blog entry, but attach it to this post, so you can take a look.
Please let me know if you have any questions upfront.
Hope that helps.
Please login first to submit.