Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 616e777
Showing
18 changed files
with
709 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
11
quote-app/src/main/java/com/example/domain/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
27
quote-app/src/main/java/com/example/web/MainController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 + | ||
'}'; | ||
} | ||
|
||
} |
Oops, something went wrong.