Difference between Vaadin 7 Push and combination of Eventbus + immediate mode - websocket

I need to update different fields (tinycon and a badge on a button similar to the one on facebook) indicating the count of unread messages of the logged in user within my Vaadin7-Webapp.
So I started to setup Vaadin 7 Push feature but without success. On latest Tomcat (tested with: 7.0.61 and 8.0.30) and latest Vaadin (7.5.10) it just did not work. No error messages, but also no push. PushDemo from https://vaadin.com/wiki/-/wiki/Main/Enabling+server+push did also nothing. I guess the antivirus software of my company interrupts the underlying websocket communication.
But at the end, I achieved the desired result (=> updating field labels dynamically during runtime based on events) without Vaadin Push but with a simple combination sending an event via an Eventbus (Guava) and setting setimmediate(true) on the related GUI fields.
Question: Does this mean that I don't need Vaadin Push at all to achieve the desired functionality or am I missing something? Which advantage do I have with Push/Websockets / Is there any downside with my actual solution or is it analogous to the Vaadin-Push one?
Shorteneded question:
(From result aspects): Vaadin 7 Push equals Eventbus + immediate fields.
?

setImmediate(true) isn't pushing or polling your server!
It just does a server roundtrip when the object is firing a event on client side.
Also see this discussion about setImmediate.
The difference between polling and push are:
Push: The server informs the client about changes, otherwise no traffic flows between both
Polling: The client asks the server every X seconds if changes have been done
setImmediate(true): Updates only when the client sends a request to the server (Mostly ba some EventListeners defined in your UI. When the user does not move the mouse, no updates will every be shown
If push is not working, better use a polling object, which does a server interaction every x seconds.
The progressbar component can be such a thing.

Related

Sinks.many() with different speed of consumers

I have dilemma, which (how) to use project reactor with real world scenario.
I have need to distribute events to all connected clients (browsers, using http and Server Sent Events). For simplicity, I am testing things as unit tests, with console subscribers.
Sample code for testing https://gist.github.com/luvarqpp/8ea6ad5ad32a8fcbf3264c00ebe351b2
My target is to make able publishing broadcast events and receive them in different browsers in different speeds.
I would like to disconnect client, when it does handle pace of events. So he will need to reconnect, to receive stream again.
PS: Sending/pushing to http can be done using SSE, simple sample code: https://gist.github.com/luvarqpp/dc941ab368504a525ac66716253b04d7
PS2: Bonus would be to be able to make "smart batching" possible to happen. i.e., when some client have X events in buffer on server side, call to custom code would make shrink of given events. Reason about events as updates to key,value database. So any update to same key can be shrunk to single update (latest value).
My approaches was using:
Sinks.many().replay().limit(0); // latest();
Sinks.many().multicast().directAllOrNothing();
Sinks.many().multicast().directBestEffort();
Sinks.many().multicast().onBackpressureBuffer(8);

How to trigger GraphQL Subscriptions from a backend message queue application

Currently I'm using Socket.io / SignalR to emit an event from my backend message queue system, whenever new data is incoming. That way I can setup an event handler in my React application and update the relay cache from within the event handler.
It does not seem like the most Graphql ish way to do things, so I was playing a bit around with pre-RFC live queries implementations, where you observed data changes in reactive data stores pushed it to the graphql server, and further to the client using websockets... with some rather complex custom code... obviously graphql is not ready for real live queries (not polling)
A few lines further down it says:
When building event-based subscriptions, the problem of determining what should trigger an event is easy, since the event defines that explicitly. It also proved fairly straight-forward to implement atop existing message queue systems.
Which leads me to my question. How can you (in a graphql way) best trigger graphql subscriptions when a new event is incoming to your backend message queue application and you need to reflect this new data in the ui in realtime - let's say each second? I'm not talking about triggering the event in the frontend/client or polling ever x seconds like you usually see when talking about subscriptions.
Not sure it's relevant but I'm using Relay Modern as my preferred graphql client.
Here's some ideas that might work if I get a little help to understand in general how to trigger/call a subscription without a mutation.
Backend worker / message queue "A" receives new incoming event with some device data. It uses either SignalR, or other pubsub (redis/socket.io/?) to notify the graphql server "B" (which subscribes to the event) about a new event has happened. The graphql server then trigger/execute the subscription and the frontend react relay application "C" automatically updates, since it has a relay subscription defined. This would be ideal, right? but how to trigger subscription on the graphql server?
Simply use Socket.io/SignalR to emit events from backend worker / message queue "A" on incoming data, subscribe and handle the event in the frontend "B", and then programically calling the subscription from within the Socket.io/SignalR event handler (if such a thing, directly calling a subscription, is even possible?). But then the only improvement from using subscriptions, instead of pure Socket.io/SignalR will be that I have moved the updating of the relay cache/store from the handler to the subscription. Not a big improvement, if any. But the manual update of the cache/store is really cumbersome, although not that hard :/
How do people handle real streaming live (device) data with signalr, and why is all realtime articles/examples just repeating the same old simple chat application, where the ui just updates after a user makes a click event? Is graphql not suited yet for dealing with a stream of frequently incoming device data in realtime? I understand why live queries was delayed after playing with implementing them myself, but without them, REAL realtime data updates and push it from the server to the frontend?

Spring Boot - Push message to Angular UI

I want to develop an application where I want to push the messages (or data) to UI from backend Spring boot application.
I have the following requirement -
Consider there is a REST service that accepts the data from other applications using the POST method.
This data will be pushed to UI.
OR
Consider that there is a background process running which generate events and we want to push these events to UI.
For this, I came across about the WebSocket component that we can use in the Spring Boot application.
However, is there any other settings required to make it possible to push the incoming data to the UI?
Any help is appreciated.
Thanks,
Avinash Deshmukh
The backend cannot magically push updates to a client UI. The backend will have no way of knowing where the UI exists (i.e. what the UI's ip address is) and even if it did, it may not have access to establish a connection (due to firewalls or a NAT).
For this reason a client UI has to request updates. One way this could be done would be to have a timer in the UI application that polls for updates via REST. But this is essentially what websockets do - with much less overhead.
This is how common applications that you use everyday work all the time. So I'm not sure why you do not want to go down the websockets route.
...
Starting with Spring 5.0.5.RELEASE, it isn’t necessary to do any customization because of the improvement of #SendToUser annotation, that allows us to send a message to a user destination via “/user/{sessionId}/…” rather than “/user/{user}/…“.
That means the annotation works relying on the session id of the input message, effectively sending a reply to destination private to the session:
...
There is a good example over here:
https://www.baeldung.com/spring-websockets-sendtouser

simple push notification in spring

I have a project that is related to job postings. Consultants or employers register on my website and then start posting jobs. I want to make push notifications for all users. When a consultant or employer posts a job, all online users must get notified that an employer has posted this job without any page refreshes on jquery setInterval or timeout.
I am using Spring framework. I have searched for the solution but found nothing. I want to know whether Spring provided WebSockets in their latest version. Is this possible to do with WebSockets?
I want a proper resource so that I can implement it on my website.
There are two ways to satisfy your need;
First is polling in which you repeatedly send requests from client to the server. On server side you somehow need have a kind of message queue for each client to deliver the incidents on a request. There also is a different type of polling in which you send a request from client and never end the request on the server-side thus you have a kind of pipe between two ends. This is called long polling.
Disadvantage of polling is that you have to send requests to the server forever from the client and in many cases server sends empty messages as there is no events happened.
The real application of pushing messages is recently avaliable with websockets (thanks to html5). However this requires the application server to be capable of websocket functionality. afaik jetty and tomcat has this ability. Spring 4 has websocket here you can find the tutorial; http://syntx.io/using-websockets-in-java-using-spring-4/
You can find a related stackoverflow post here

GWT client state

I am starting to use gwt and I am having some problems to identify the clients state.
I am using GWTEventService to push some data to the client. But this data depends on which tab the client is. But how to know the state of the client (eg. which is the radio button selected)without using cookies. As I am sending events each 5 seconds, check the client state using cookies to each event that I want to send would make the application become very slow.
Can anyone help me?
Thank you,
Maurício
I would suggest a different design approach. Instead of pushing data to the client, have the client pull the data from the server. I have used GWT-RPC extensively to do this: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html
If that approach doesn't work for you, the next best approach, whenever the state of the client changes, notify the server, so it always knows the state. You could then to client tracking with sessions.

Resources