Skip to content

Commit 796ac66

Browse files
committed
Added Spring-WebFlux Functional approach
Also added mongo-docker to work with MongoDB examples.
1 parent 80c4ff8 commit 796ac66

File tree

9 files changed

+93
-0
lines changed

9 files changed

+93
-0
lines changed

mongo-docker/docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Mongo docker image
2+
version: '3.1'
3+
4+
services:
5+
mongo:
6+
image: 'mongo:4.4.0-rc8-bionic'
7+
restart: on-failure
8+
ports:
9+
- 27017:27017
10+
environment:
11+
MONGO_INITDB_ROOT_USERNAME: root
12+
MONGO_INITDB_ROOT_PASSWORD: root@123
13+
14+
mongo-express:
15+
image: mongo-express
16+
restart: always
17+
ports:
18+
- 8081:8081
19+
environment:
20+
ME_CONFIG_MONGODB_ADMINUSERNAME: root
21+
ME_CONFIG_MONGODB_ADMINPASSWORD: root@123

webflux-00-controller-approach/README.md

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package c.jbd.webflux.resources;
2+
3+
public class CorrectTestController {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package c.jbd.webflux.resources;
2+
3+
public class TestHelloController {
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-webflux-tutorial</artifactId>
7+
<groupId>com.jstobigdata</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>webflux-01-functional-approach</artifactId>
13+
14+
15+
</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 FunctionalAppConfig {
8+
public static void main(String[] args) {
9+
SpringApplication.run(AppConfig.class, args);
10+
}
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package c.jbd.webflux;
2+
3+
import org.springframework.http.MediaType;
4+
import org.springframework.stereotype.Component;
5+
import org.springframework.web.reactive.function.server.ServerRequest;
6+
import org.springframework.web.reactive.function.server.ServerResponse;
7+
import reactor.core.publisher.Flux;
8+
import reactor.core.publisher.Mono;
9+
10+
import java.time.Duration;
11+
12+
@Component
13+
public class HelloHandlerFunction {
14+
public Mono<ServerResponse> monoMessage(ServerRequest request) {
15+
return ServerResponse.ok()
16+
.contentType(MediaType.TEXT_PLAIN)
17+
.body(
18+
Mono.just("Welcome to JstoBigdata.com"), String.class
19+
);
20+
}
21+
22+
public Mono<ServerResponse> fluxMessage(ServerRequest request) {
23+
return ServerResponse.ok()
24+
.contentType(MediaType.APPLICATION_STREAM_JSON)
25+
.body(
26+
Flux.just("Welcome ", "to ", "JstoBigdata.com")
27+
.delayElements(Duration.ofSeconds(1)).log(), String.class
28+
);
29+
}
30+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package c.jbd.webflux;
2+
3+
public class HelloRouter {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package c.jbd.webflux;
2+
3+
public class FunctionalAppTest {
4+
}

0 commit comments

Comments
 (0)