Skip to content

Commit 80c4ff8

Browse files
committed
Added code for WebFlux getting started module
1 parent 8d62cf1 commit 80c4ff8

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
7+
<parent>
8+
<artifactId>spring-webflux-tutorial</artifactId>
9+
<groupId>com.jstobigdata</groupId>
10+
<version>1.0-SNAPSHOT</version>
11+
</parent>
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>webflux-00-controller-approach</artifactId>
14+
<description>First WebFlux project in Spring boot</description>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-webflux</artifactId>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-test</artifactId>
25+
<scope>test</scope>
26+
<exclusions>
27+
<exclusion>
28+
<groupId>org.junit.vintage</groupId>
29+
<artifactId>junit-vintage-engine</artifactId>
30+
</exclusion>
31+
</exclusions>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>io.projectreactor</groupId>
36+
<artifactId>reactor-test</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-devtools</artifactId>
43+
<optional>true</optional>
44+
<scope>runtime</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package c.jbd.webflux;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class AppConfig {
8+
public static void main(String[] args) {
9+
SpringApplication.run(AppConfig.class, args);
10+
}
11+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package c.jbd.webflux.model;
2+
3+
import java.time.LocalDate;
4+
import java.util.StringJoiner;
5+
6+
public class Message {
7+
private LocalDate date;
8+
private String greeting;
9+
private String ipAddress;
10+
11+
public LocalDate getDate() {
12+
return date;
13+
}
14+
15+
public Message setDate(LocalDate date) {
16+
this.date = date;
17+
return this;
18+
}
19+
20+
public String getGreeting() {
21+
return greeting;
22+
}
23+
24+
public Message setGreeting(String greeting) {
25+
this.greeting = greeting;
26+
return this;
27+
}
28+
29+
public String getIpAddress() {
30+
return ipAddress;
31+
}
32+
33+
public Message setIpAddress(String ipAddress) {
34+
this.ipAddress = ipAddress;
35+
return this;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return new StringJoiner(", ", Message.class.getSimpleName() + "[", "]")
41+
.add("date=" + date)
42+
.add("greeting='" + greeting + "'")
43+
.add("ipAddress='" + ipAddress + "'")
44+
.toString();
45+
}
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package c.jbd.webflux.resources;
2+
3+
import org.springframework.http.MediaType;
4+
import org.springframework.web.bind.annotation.*;
5+
import reactor.core.publisher.Flux;
6+
import reactor.core.publisher.Mono;
7+
8+
import java.time.Duration;
9+
10+
@RestController
11+
@RequestMapping("/hello")
12+
public class HelloController {
13+
14+
@GetMapping(path = "/mono")
15+
public Mono<String> getMono(){
16+
return Mono.just("Welcome to JstoBigdata.com");
17+
}
18+
19+
@GetMapping(path = "/flux", produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
20+
public Flux<String> getFlux(){
21+
Flux<String> msg$ = Flux.just("Welcome ", "to ", "JstoBigdata.com")
22+
.delayElements(Duration.ofSeconds(1)).log();
23+
return msg$;
24+
}
25+
26+
//@GetMapping
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package c.jbd.webflux.resources;
2+
3+
import org.springframework.web.bind.annotation.ExceptionHandler;
4+
import org.springframework.web.bind.annotation.RestControllerAdvice;
5+
6+
@RestControllerAdvice
7+
public class RestAdvice {
8+
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server:
2+
port: 8080

0 commit comments

Comments
 (0)