Send BackgroundTasks notifications based on client criteria

1
0

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 …

  • You must to post comments
1
0

Here is the updated sample.

  • You must to post comments
0
0

Hi Luca,
can you please provide the timer based sample (for environments which do not allow websockets) to me ?

  • You must to post comments
0
0

Hi Luca,

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…

 

  • Luca (ITG)
    Yes, it’s because WebSocket is probably not working at that site. demo.wisej.com cannot work with https because it doesn’t have a certificate. The updates will go to the client at the first request *from* the client since the connection is http and not websocket (you can verify with F12 in chrome, it gets logged). It’s easy to solve by adding a timer for clients that don’t support websocket. I’ll add to the sample.
  • Tobias
    You seem to be right. There are entries about WebSocket errors in the dev console of Firefox. I’ll try to put this stuff on a server with a certificate tomorrow and do another test…
  • Tobias
    Hi Luca, did you already find some spare time to add the timer to the sample to support clients which do not support websockets ?
  • You must to post comments
0
0

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.

HTH

[Edited] You can also try it here: http://demo.wisej.com/stockquotes

/Luca

  • You must to post comments
2
0

Hi Tobias,

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.

HTH

/Luca

  • You must to post comments
0
0

Hi Frank,
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…

 

 

  • You must to post comments
0
0

Hi Tobias,

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:

screen

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:

screen2

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.

Best regards
Frank

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.