This article gives overview of RxJava Observables for listening Spring Server Sent Events. "Server Sent Events are stream of data/events which are emitted from Server to Client for a HTTP request on single HTTP connection".
Rx Java is reactive extension of Java Virtual Machine which defines APIs knowns as "Observables, Flowables, Single" etc using which we can write client code for both ASYNC programming or SYNC requests, hardly any change in the code here.
Following example shows how we can consume single ASYNC event and also Stream of ASYNC events using Rx Java Observables
Rx Java is reactive extension of Java Virtual Machine which defines APIs knowns as "Observables, Flowables, Single" etc using which we can write client code for both ASYNC programming or SYNC requests, hardly any change in the code here.
Following example shows how we can consume single ASYNC event and also Stream of ASYNC events using Rx Java Observables
Client Side : Example3.java
Client Side: Util.java
Server Side Code - Spring Server Sent Events for above observables to listen. This server side spring boot application will host endpoint http://localhost:4545/alerts which emits stream of events and for single data endpoint we are hitting this endpoint http://freegeoip.net/json/ which returns current location of that machine
Code snippet for Server Sent Events