Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b11caeb3
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b11caeb3
编写于
10月 05, 2017
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix headings in WebFlux section
上级
ee3913c6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
61 deletion
+57
-61
src/docs/asciidoc/web-reactive.adoc
src/docs/asciidoc/web-reactive.adoc
+57
-4
src/docs/asciidoc/web/webflux.adoc
src/docs/asciidoc/web/webflux.adoc
+0
-57
未找到文件。
src/docs/asciidoc/web-reactive.adoc
浏览文件 @
b11caeb3
...
...
@@ -7,9 +7,62 @@
:docinfo1:
This part of the documentation covers support for reactive stack, web applications built on a
http://www.reactive-streams.org/[Reactive Streams] API to run on
top of
non-blocking
http://www.reactive-streams.org/[Reactive Streams] API to run on non-blocking
servers such as Netty, Undertow, and Servlet 3.1+ containers. Individual chapters cover
<<webflux-module, Spring WebFlux>> and its <<webflux-fn,functional programming model>>.
For Servlet stack, web applications, to go <<web.adoc#spring-web,Web on Servlet Stack>>.
the <<webflux-module,Spring WebFlux>> framework,
the reactive <<webflux-client,WebClient>>, support for <<webflux-test>>,
and <<webflux-reactive-libraries>>. For Servlet stack, web applications, please see
<<web.adoc#spring-web,Web on Servlet Stack>>.
include::web/webflux.adoc[leveloffset=+1]
\ No newline at end of file
include::web/webflux.adoc[leveloffset=+1]
include::web/webflux-webclient.adoc[leveloffset=+1]
[[webflux-test]]
== Testing
The `spring-test` module provides mock implementations of `ServerHttpRequest`,
`ServerHttpResponse`, and `ServerWebExchange`.
See <<testing.adoc#mock-objects-web-reactive,Spring Web Reactive>> mock objects.
The <<testing.adoc#webtestclient,WebTestClient>> builds on these mock request and
response objects to provide support for testing WebFlux applications without and HTTP
server. The `WebTestClient` can be used for end-to-end integration tests too.
[[webflux-reactive-libraries]]
== Reactive Libraries
Reactor is a required dependency for the `spring-webflux` module and is used internally
for composing logic and for Reactive Streams support. An easy rule to remember is that
WebFlux APIs return `Flux` or `Mono` -- since that's what's used internally, and
leniently accept any Reactive Streams `Publisher` implementation.
The use of `Flux` and `Mono` helps to express cardinality -- e.g.
whether a single or multiple async values are expected. This is important for API design
but also essential in some cases, e.g. when encoding an HTTP message.
For annotated controllers, WebFlux adapts transparently to the reactive library in use
with proper translation of cardinality. This is done with the help of the
{api-spring-framework}/core/ReactiveAdapterRegistry.html[ReactiveAdapterRegistry] from
`spring-core` which provides pluggable support for reactive and async types. The registry
has built-in support for RxJava and `CompletableFuture` but others can be registered.
For functional endpoints, the `WebClient`, and other functional APIs, the general rule
of thumb for WebFlux APIs applies:
* `Flux` or `Mono` as return values -- use them to compose logic or pass to any Reactive
Streams library (both are `Publisher` implementations).
* Reactive Streams `Publisher` for input -- if a `Publisher` from another reactive library
is provided it can only be treated as a stream with unknown semantics (0..N). If the
semantics are known -- e.g. `io.reactivex.Single`, you can use `Mono.from(Publisher)` and
pass that in instead of the raw `Publisher`.
[NOTE]
====
For example, given a `Publisher` that is not a `Mono`, the Jackson JSON message writer
expects multiple values. If the media type implies an infinite stream -- e.g.
`"application/json+stream"`, values are written and flushed individually; otherwise
values are buffered into a list and rendered as a JSON array.
====
src/docs/asciidoc/web/webflux.adoc
浏览文件 @
b11caeb3
...
...
@@ -16,11 +16,6 @@ and co-exist side by side in the Spring Framework. Each module is optional.
Applications
may
use
one
or
the
other
module
,
or
in
some
cases
both
--
e
.
g
.
Spring
MVC
controllers
with
the
reactive
`
WebClient
`.
The
`
spring
-
webflux
`
module
also
provides
a
reactive
<<
webflux
-
client
,
WebClient
>>
for
performing
HTTP
requests
,
along
with
client
and
server
,
reactive
WebSocket
support
.
The
`
spring
-
test
`
module
provides
test
support
for
WebFlux
applications
,
see
<<
webflux
-
test
>>
for
more
details
.
[[
webflux
-
new
-
framework
]]
===
Why
a
new
web
framework
?
...
...
@@ -1387,55 +1382,3 @@ from the base class and you can still have any number of other ``WebMvcConfigure
the classpath.
include::webflux-webclient.adoc[leveloffset=+1]
[[webflux-test]]
== Testing
The `spring-test` module provides mock implementations of `ServerHttpRequest`,
`ServerHttpResponse`, and `ServerWebExchange`.
See <<testing.adoc#mock-objects-web-reactive,Spring Web Reactive>> mock objects.
The <<testing.adoc#webtestclient,WebTestClient>> builds on these mock request and
response objects to provide support for testing WebFlux applications without and HTTP
server. The `WebTestClient` can be used for end-to-end integration tests too.
[[webflux-reactive-libraries]]
== Reactive Libraries
Reactor is a required dependency for the `spring-webflux` module and is used internally
for composing logic and for Reactive Streams support. An easy rule to remember is that
WebFlux APIs return `Flux` or `Mono` -- since that'
s
what
's used internally, and
leniently accept any Reactive Streams `Publisher` implementation.
The use of `Flux` and `Mono` helps to express cardinality -- e.g.
whether a single or multiple async values are expected. This is important for API design
but also essential in some cases, e.g. when encoding an HTTP message.
For annotated controllers, WebFlux adapts transparently to the reactive library in use
with proper translation of cardinality. This is done with the help of the
{api-spring-framework}/core/ReactiveAdapterRegistry.html[ReactiveAdapterRegistry] from
`spring-core` which provides pluggable support for reactive and async types. The registry
has built-in support for RxJava and `CompletableFuture` but others can be registered.
For functional endpoints, the `WebClient`, and other functional APIs, the general rule
of thumb for WebFlux APIs applies:
* `Flux` or `Mono` as return values -- use them to compose logic or pass to any Reactive
Streams library (both are `Publisher` implementations).
* Reactive Streams `Publisher` for input -- if a `Publisher` from another reactive library
is provided it can only be treated as a stream with unknown semantics (0..N). If the
semantics are known -- e.g. `io.reactivex.Single`, you can use `Mono.from(Publisher)` and
pass that in instead of the raw `Publisher`.
[NOTE]
====
For example, given a `Publisher` that is not a `Mono`, the Jackson JSON message writer
expects multiple values. If the media type implies an infinite stream -- e.g.
`"application/json+stream"`, values are written and flushed individually; otherwise
values are buffered into a list and rendered as a JSON array.
====
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录