Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed May 17, 2017
0 parents commit 616e777
Show file tree
Hide file tree
Showing 18 changed files with 709 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
14 changes: 14 additions & 0 deletions README.md
@@ -0,0 +1,14 @@
# Web flux streaming demo

This demo application showcases some of the features of the reactive support in Spring
Framework 5.

`quote-service` is a functional-based kotlin service that emits a "random" quote every
200ms, either as server-sent events (SSE) or json stream.

`quote-app` uses embedded MongoDB and the upcoming reactive MongoDB support to showcase
how a template engine can integrate with this new paradigm. It also has a UI that uses
display the value of a set of actions live. For that, it uses the new `WebClient` API on
the server side to get the values from the `quote-service` in a reactive fashion.

To run the demo, simply start the two apps and go to `http://localhost:8080`.
81 changes: 81 additions & 0 deletions pom.xml
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M1</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>demo-webflux-streaming</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WebFlux streaming demo</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<modules>
<module>quote-app</module>
<module>quote-service</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>highcharts</artifactId>
<version>5.0.8</version>
</dependency>
</dependencies>
</dependencyManagement>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
67 changes: 67 additions & 0 deletions quote-app/pom.xml
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>demo-webflux-streaming</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>quote-app</artifactId>
<packaging>jar</packaging>
<name>Quote App</name>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>highcharts</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
37 changes: 37 additions & 0 deletions quote-app/src/main/java/com/example/QuoteApplication.java
@@ -0,0 +1,37 @@
package com.example;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

import com.example.domain.User;
import com.example.domain.UserRepository;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class QuoteApplication {

public static void main(String[] args) {
SpringApplication.run(QuoteApplication.class, args);
}

@Bean
public CommandLineRunner createUsers(UserRepository userRepository) {
return strings -> {
List<User> users = Arrays.asList(
new User("sdeleuze", "Sebastien Deleuze"),
new User("bclozel", "Brian Clozel"),
new User("rstoyanchev", "Rossen Stoyanchev"),
new User("smaldini", "Stephane Maldini"),
new User("sbasle", "Simon Basle"),
new User("snicoll", "Stephane Nicoll")
);
userRepository.saveAll(users).blockLast(Duration.ofSeconds(3));
};
}

}
48 changes: 48 additions & 0 deletions quote-app/src/main/java/com/example/domain/User.java
@@ -0,0 +1,48 @@
package com.example.domain;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document
public class User {

@Id
private String id;

private String github;

private String name;

public User() {
}

public User(String github, String name) {
this.github = github;
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getGithub() {
return github;
}

public void setGithub(String github) {
this.github = github;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}
11 changes: 11 additions & 0 deletions quote-app/src/main/java/com/example/domain/UserRepository.java
@@ -0,0 +1,11 @@
package com.example.domain;

import reactor.core.publisher.Mono;

import org.springframework.data.mongodb.repository.ReactiveMongoRepository;

public interface UserRepository extends ReactiveMongoRepository<User, String> {

Mono<User> findUserByGithub(String github);

}
27 changes: 27 additions & 0 deletions quote-app/src/main/java/com/example/web/MainController.java
@@ -0,0 +1,27 @@
package com.example.web;

import com.example.domain.UserRepository;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class MainController {

private final UserRepository userRepository;

public MainController(UserRepository userRepository) {
this.userRepository = userRepository;
}

@GetMapping("/")
public String home() {
return "index";
}

@GetMapping("/quotes")
public String quotes() {
return "quotes";
}

}
66 changes: 66 additions & 0 deletions quote-app/src/main/java/com/example/web/Quote.java
@@ -0,0 +1,66 @@
package com.example.web;

import java.math.BigDecimal;
import java.math.MathContext;
import java.time.Instant;

class Quote {

private static final MathContext MATH_CONTEXT = new MathContext(2);

private String ticker;

private BigDecimal price;

private Instant instant;

public Quote() {
}

public Quote(String ticker, BigDecimal price) {
this.ticker = ticker;
this.price = price;
}

public Quote(String ticker, Double price) {
this(ticker, new BigDecimal(price, MATH_CONTEXT));
}

public String getTicker() {
return ticker;
}

public void setTicker(String ticker) {
this.ticker = ticker;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public Instant getInstant() {
return instant;
}

public void setInstant(Instant instant) {
this.instant = instant;
}

public void setInstant(long epoch) {
this.instant = Instant.ofEpochSecond(epoch);
}

@Override
public String toString() {
return "Quote{" +
"ticker='" + ticker + '\'' +
", price=" + price +
", instant=" + instant +
'}';
}

}

0 comments on commit 616e777

Please sign in to comment.