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
相关推荐
罗政2 小时前
[附源码]超简洁个人博客网站搭建+SpringBoot+Vue前后端分离
vue.js·spring boot·后端
架构文摘JGWZ3 小时前
Java 23 的12 个新特性!!
java·开发语言·学习
拾光师4 小时前
spring获取当前request
java·后端·spring
aPurpleBerry4 小时前
neo4j安装启动教程+对应的jdk配置
java·neo4j
我是苏苏4 小时前
Web开发:ABP框架2——入门级别的增删改查Demo
java·开发语言
xujinwei_gingko4 小时前
Spring IOC容器Bean对象管理-Java Config方式
java·spring
2301_789985944 小时前
Java语言程序设计基础篇_编程练习题*18.29(某个目录下的文件数目)
java·开发语言·学习
IT学长编程4 小时前
计算机毕业设计 教师科研信息管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解
java·毕业设计·springboot·毕业论文·计算机毕业设计选题·计算机毕业设计开题报告·教师科研管理系统
m0_571957584 小时前
Java | Leetcode Java题解之第406题根据身高重建队列
java·leetcode·题解
程序猿小D4 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa