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
相关推荐
Felix666yy13 分钟前
设计模式之建造者模式
java
界面开发小八哥14 分钟前
「Java EE开发指南」如何使用Visual JSF编辑器设计JSP?(一)
java·ide·java-ee·编辑器·myeclipse
先睡16 分钟前
javaEE
java·java-ee
冷心笑看丽美人17 分钟前
Spring 框架七大模块(Java EE 学习笔记03)
学习·spring·架构·java-ee
程序猿小D24 分钟前
第三百三十一节 Java网络教程 - Java网络UDP多播
java·网络·udp
灭掉c与java27 分钟前
第五章springboot实现web的常用功能
java·spring boot·spring
初晴~39 分钟前
【Spring】RESTful设计风格
java·后端·spring·springboot·restful
风动也无爱1 小时前
Java的正则表达式和爬虫
java·爬虫·正则表达式
訴山海1 小时前
解决Excel文件流读取数字为时间乱码问题
java·文件流
今日之风甚是温和1 小时前
【Excel】拆分多个sheet,为单一表格
java·excel·sheet·vb宏