This is a sample implementation of a Spring Web Flux client that connects to an Server-Sent Events Source provided by the streamdata.io service. Apart from Spring Web Flux, this demo uses zjsonpatch as a Java Json-Patch implementation. zjsonpatch relies itself on Jackson a Java Json library.
-
Create an free account on streamdata.io https://portal.streamdata.io/#/register to get an App token.
-
Clone project, edit Main.java and replace
[YOUR TOKEN HERE]
with your App token. -
Make sure you have Java 8+ installed
-
Make sure you have maven 3.0+ installed
-
Build project with maven:
mvn clean install
- Run sample from a terminal:
java -jar target/streamdataio-spring-webflux-0.0.1-SNAPSHOT.jar
or
mvn clean spring-boot:run
You should see data and patches pushed in your application and displayed on your terminal.
You can use the provided demo example API which simulates updating stocks prices from a financial market: 'http://stockmarket.streamdata.io/prices'
Feel free to test it with any REST/Json API of your choice.
This is a fairly basic implementation and can be viewed more as a starting point for your own implementation.
Dependening on your use-case, you may enhance:
- the error handling (retry, etc.) but by keeping in mind that is wiser to close the connection if "fatal" errors are received (errors that should stop any processing, etc.)
- patch handling
- ...
A blog post is published here