Reactor Netty-响应式编程-010

🤗 ApiHug × {Postman|Swagger|Api...} = 快↑ 准√ 省↓

  1. GitHub - apihug/apihug.com: All abou the Apihug
  2. apihug.com: 有爱,有温度,有质量,有信任
  3. ApiHug - API design Copilot - IntelliJ IDEs Plugin | Marketplace

为什么不直接上来就 Netty 或者 Spring WebFlux ?

出于几点考虑:

  1. 本身 Netty 学习曲线稍微陡峭
  2. 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 及以上的版本上。

它需要依赖于以下组件:

  1. Reactive Streams v1.0.4
  2. Reactor Core v3.x
  3. 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 (*)

#参考

  1. Reactor Netty 官方文档open in new window
  2. reactor-netty-demo 学习open in new window
  3. Reactor Netty Workshopopen in new window
  4. reactor-netty API
相关推荐
为将者,自当识天晓地。15 分钟前
c++多线程
java·开发语言
daqinzl23 分钟前
java获取机器ip、mac
java·mac·ip
激流丶39 分钟前
【Kafka 实战】如何解决Kafka Topic数量过多带来的性能问题?
java·大数据·kafka·topic
Themberfue42 分钟前
Java多线程详解⑤(全程干货!!!)线程安全问题 || 锁 || synchronized
java·开发语言·线程·多线程·synchronized·
让学习成为一种生活方式1 小时前
R包下载太慢安装中止的解决策略-R语言003
java·数据库·r语言
晨曦_子画1 小时前
编程语言之战:AI 之后的 Kotlin 与 Java
android·java·开发语言·人工智能·kotlin
南宫生1 小时前
贪心算法习题其三【力扣】【算法学习day.20】
java·数据结构·学习·算法·leetcode·贪心算法
Heavydrink2 小时前
HTTP动词与状态码
java
ktkiko112 小时前
Java中的远程方法调用——RPC详解
java·开发语言·rpc
计算机-秋大田2 小时前
基于Spring Boot的船舶监造系统的设计与实现,LW+源码+讲解
java·论文阅读·spring boot·后端·vue