🤗 ApiHug × {Postman|Swagger|Api...} = 快↑ 准√ 省↓
- GitHub - apihug/apihug.com: All abou the Apihug
- apihug.com: 有爱,有温度,有质量,有信任
- ApiHug - API design Copilot - IntelliJ IDEs Plugin | Marketplace
为什么不直接上来就 Netty 或者 Spring WebFlux ?
出于几点考虑:
- 本身 Netty 学习曲线稍微陡峭
- Spring WebFlux 封装很多细节
所以选择一个 Reactor --> Reactor Netty --> Spring WebFlux
这样一个渐进的线路。
Reactor Netty 官方文档open in new window,最新资料参考官网更新, 学习例子: reactor-netty-demo 学习open in new window。
#关于
Suited for Microservices Architecture, Reactor Netty offers backpressure-ready network engines for HTTP (including Websockets), TCP, and UDP.
适合于微服务架构,Reactor Netty为HTTP(包括Websocket),TCP和UDP提供了支持背压的网络引擎。
#前提
Reactor Netty需要运行在Java 8 及以上的版本上。
它需要依赖于以下组件:
- Reactive Streams v1.0.4
- Reactor Core v3.x
- Netty v4.1.x
#项目依赖
都走BOM 走了非常简单:
dependencies {
// import a BOM
implementation platform('io.projectreactor:reactor-bom:2020.0.21')
// define dependencies without versions
implementation 'io.projectreactor.netty:reactor-netty-core'
implementation 'io.projectreactor.netty:reactor-netty-http'
}
依赖关系如下:
------------------------------------------------------------
| BOM 依赖
------------------------------------------------------------
+--- io.projectreactor:reactor-bom:2020.0.21
| +--- io.projectreactor.netty:reactor-netty-core:1.0.21 (c)
| +--- io.projectreactor.netty:reactor-netty-http:1.0.21 (c)
| +--- io.projectreactor:reactor-core:3.4.21 (c)
| \--- org.reactivestreams:reactive-streams:1.0.4 (c)
------------------------------------------------------------
| 下面是具体版本
------------------------------------------------------------
+--- io.projectreactor.netty:reactor-netty-core -> 1.0.21
| +--- io.netty:netty-handler:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-resolver:4.1.79.Final
| | | \--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final
| | | \--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-transport:4.1.79.Final
| | | +--- io.netty:netty-common:4.1.79.Final
| | | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | | \--- io.netty:netty-resolver:4.1.79.Final (*)
| | +--- io.netty:netty-transport-native-unix-common:4.1.79.Final
| | | +--- io.netty:netty-common:4.1.79.Final
| | | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | | \--- io.netty:netty-transport:4.1.79.Final (*)
| | \--- io.netty:netty-codec:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | \--- io.netty:netty-transport:4.1.79.Final (*)
| +--- io.netty:netty-handler-proxy:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | +--- io.netty:netty-transport:4.1.79.Final (*)
| | +--- io.netty:netty-codec:4.1.79.Final (*)
| | +--- io.netty:netty-codec-socks:4.1.79.Final
| | | +--- io.netty:netty-common:4.1.79.Final
| | | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | | +--- io.netty:netty-transport:4.1.79.Final (*)
| | | \--- io.netty:netty-codec:4.1.79.Final (*)
| | \--- io.netty:netty-codec-http:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | +--- io.netty:netty-transport:4.1.79.Final (*)
| | +--- io.netty:netty-codec:4.1.79.Final (*)
| | \--- io.netty:netty-handler:4.1.79.Final (*)
| +--- io.netty:netty-resolver-dns:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | +--- io.netty:netty-resolver:4.1.79.Final (*)
| | +--- io.netty:netty-transport:4.1.79.Final (*)
| | +--- io.netty:netty-codec:4.1.79.Final (*)
| | +--- io.netty:netty-codec-dns:4.1.79.Final
| | | +--- io.netty:netty-common:4.1.79.Final
| | | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | | +--- io.netty:netty-transport:4.1.79.Final (*)
| | | \--- io.netty:netty-codec:4.1.79.Final (*)
| | \--- io.netty:netty-handler:4.1.79.Final (*)
| +--- io.netty:netty-resolver-dns-native-macos:4.1.79.Final
| | \--- io.netty:netty-resolver-dns-classes-macos:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-resolver-dns:4.1.79.Final (*)
| | \--- io.netty:netty-transport-native-unix-common:4.1.79.Final (*)
| +--- io.netty:netty-transport-native-epoll:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | +--- io.netty:netty-transport:4.1.79.Final (*)
| | +--- io.netty:netty-transport-native-unix-common:4.1.79.Final (*)
| | \--- io.netty:netty-transport-classes-epoll:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | +--- io.netty:netty-transport:4.1.79.Final (*)
| | \--- io.netty:netty-transport-native-unix-common:4.1.79.Final (*)
| \--- io.projectreactor:reactor-core:3.4.20 -> 3.4.21
| \--- org.reactivestreams:reactive-streams:1.0.4
------------------------------------------------------------
| HTTP
------------------------------------------------------------
+--- io.projectreactor.netty:reactor-netty-http -> 1.0.21
| +--- io.netty:netty-codec-http:4.1.79.Final (*)
| +--- io.netty:netty-codec-http2:4.1.79.Final
| | +--- io.netty:netty-common:4.1.79.Final
| | +--- io.netty:netty-buffer:4.1.79.Final (*)
| | +--- io.netty:netty-transport:4.1.79.Final (*)
| | +--- io.netty:netty-codec:4.1.79.Final (*)
| | +--- io.netty:netty-handler:4.1.79.Final (*)
| | \--- io.netty:netty-codec-http:4.1.79.Final (*)
| +--- io.netty:netty-resolver-dns:4.1.79.Final (*)
| +--- io.netty:netty-resolver-dns-native-macos:4.1.79.Final (*)
| +--- io.netty:netty-transport-native-epoll:4.1.79.Final (*)
| +--- io.projectreactor.netty:reactor-netty-core:1.0.21 (*)
| \--- io.projectreactor:reactor-core:3.4.20 -> 3.4.21 (*)
#参考
- Reactor Netty 官方文档open in new window
- reactor-netty-demo 学习open in new window
- Reactor Netty Workshopopen in new window
- reactor-netty API