Skip to content

Composing JVM Futures (Guava, Java8, RxJava, Akka) with SpringRest on top of SpringBoot

Notifications You must be signed in to change notification settings

vhoang55/spring-rest-futures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot Rest comibines with JVM Futures from the following libraries

  1. Guava
  2. Rxjava
  3. Akka Futures(and actor)
  4. Java8 Completable Futures

Compare the Synchronous version vs different Asynchronous, the response time is significantly reduced from ~5 seconds to 1 - 1.5 seconds

To run the project, clone it, and import it into your favorite IDE.

The main entry point of the application is

SpringBootFuturesSimulation,

public class SpringBootFuturesSimulation {

public static void main(String[] args)  {

    Runtime.getRuntime().addShutdownHook(new Thread(SpringBootFuturesSimulation::shutdown));

    new SpringApplicationBuilder(SpringWebFuturesApplication.class)
            .showBanner(false)
            .properties("server.port=${main.port}")
            .run();


    new SpringApplicationBuilder(CalculationEngineApp.class)
            .showBanner(false)
            .properties("server.port=${calculationEngine.port}")
            .run();

    new SpringApplicationBuilder(DestinationEngineApp.class)
            .showBanner(false)
            .properties("server.port=${destinationEngine.port}")
            .run();


    new SpringApplicationBuilder(ForecastEngineApp.class)
            .showBanner(false)
            .properties("server.port=${forecastEngine.port}")
            .run();

}

}

this will launch up to 4 instances of embedded tomcats (mainly we want to simulate making external web service calls) make sure ports 8080 - 8084 are clear...

Once the application startup, navigate to http://localhost:8080/index.html to see the application

once you click on the Load Data Button on each tab, an angularjs controller will fetch the data from the SpringRest controller and render the response with the processing time for each call.

here is a simple response from server:

{
  "visited": [
    {"destination": "Denmark"},
    {"destination": "Haiti"},
    {"destination": "Lebanon"},
    {"destination": "Vietnam"},
    {"destination": "Dominica"}
  ],
  "recommended": [
    {
      "destination": "Rwanda",
      "forecast": "Storm",
      "price": 330
    },
    {
      "destination": "Kenya",
      "forecast": "Snow",
      "price": 2149
    },
    {
      "destination": "St. Vincent & The Grenadines",
      "forecast": "Snow",
      "price": 4537
    },
    {
      "destination": "Palau",
      "forecast": "Sleet",
      "price": 6669
    },
    {
      "destination": "Bangladesh",
      "forecast": "Scattered Showers",
      "price": 7766
    }
  ],
  "processingTime": 1464
}

I will write some blog entries about SpringBoot, and and composing Futures with Guava, Java8, Rxjava, Akka shortly..

the blog could be found at: https://randomthought2015.wordpress.com/

About

Composing JVM Futures (Guava, Java8, RxJava, Akka) with SpringRest on top of SpringBoot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published