Skip to content

Commit

Permalink
✨ Reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sanshengshui committed Dec 10, 2019
1 parent 9b98f2d commit 83d4e76
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 0 deletions.
55 changes: 55 additions & 0 deletions netty-webflux/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.sanshengshui</groupId>
<artifactId>netty-webflux</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>netty :: Webflux</name>

<description>netty 之响应式编程</description>

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

<dependencies>
<!-- 实现对 Spring WebFlux 的自动化配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<!-- 方便等会写单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sanshengshui.webflux;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author james mu
* @date 2019/12/10 17:16
*/
@SpringBootApplication
public class Application {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.sanshengshui.webflux.controller;

import com.sanshengshui.webflux.vo.UserVO;
import org.reactivestreams.Publisher;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;

/**
* @author james mu
* @date 2019/12/10 18:02
*/
@RestController
@RequestMapping("/users")
public class UserController {

@GetMapping("/list")
public Flux<UserVO> list() {
List<UserVO> result = new ArrayList<>();
UserVO userVO = new UserVO();
userVO.setId(1);
userVO.setUsername("mushuwei");
result.add(userVO);

UserVO userVO1 = new UserVO();
userVO1.setId(2);
userVO1.setUsername("sanshengshui");
result.add(userVO1);

UserVO userVO2 = new UserVO();
userVO2.setId(3);
userVO2.setUsername("jamesmsw");
result.add(userVO2);

return Flux.fromIterable(result);
}

@GetMapping("/get")
public Mono<UserVO> get(@RequestParam("id") Integer id) {
UserVO userVO = new UserVO();
userVO.setId(id);
userVO.setUsername("mushuwei");
return Mono.just(userVO);
}

@PostMapping("add")
public Mono<Integer> add(@RequestBody Publisher<UserVO> addVO) {
Integer returunId = 1;
return Mono.just(returunId);
}

@PostMapping("/update")
public Mono<Boolean> update(@RequestBody Publisher<UserVO> updateVO) {
Boolean success = true;
return Mono.just(success);
}

@PostMapping("/delete")
public Mono<Boolean> delete(@RequestParam("id") Integer id) {
Boolean success = false;
return Mono.just(success);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sanshengshui.webflux.vo;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
* @author james mu
* @date 2019/12/10 17:31
*/
@Data
@ToString
public class UserVO implements Serializable {

private Integer id;

private String username;

}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<module>netty-helloworld</module>
<!-- netty 之 实现高性能http服务器-->
<module>netty-http</module>
<!-- netty 之 响应式编程-->
<module>netty-webflux</module>
<!-- netty 之 netty整合springboot并使用protobuf进行数据传输-->
<module>netty-springboot-protobuf</module>
<!--netty之 netty 整合 Kafka producer-->
Expand Down

0 comments on commit 83d4e76

Please sign in to comment.