reactor netty
v1.2.1
Reactor Netty
提供基於Netty
框架的非阻塞和背壓就緒的TCP
/ HTTP
/ UDP
/ QUIC
客戶端和伺服器。
Reactor Netty
需要 Java 8 或 + 才能運作。
使用 repo.spring.io 或Maven Central
儲存庫中的Gradle
(僅限穩定版本):
repositories {
// maven { url 'https://repo.spring.io/snapshot' }
maven { url ' https://repo.spring.io/milestone ' }
mavenCentral()
}
dependencies {
// compile "io.projectreactor.netty:reactor-netty-core:1.2.2-SNAPSHOT"
compile " io.projectreactor.netty:reactor-netty-core:1.2.1 "
// compile "io.projectreactor.netty:reactor-netty-http:1.2.2-SNAPSHOT"
compile " io.projectreactor.netty:reactor-netty-http:1.2.1 "
}
有關獲取它的更多信息,請參閱參考文件(例如,使用Maven
或如何獲取里程碑和快照)。
Reactor Netty
新手?查看 Reactor Netty Workshop 和參考文檔
這是一個非常簡單的HTTP
伺服器和對應的HTTP
客戶端範例
HttpServer . create () // Prepares an HTTP server ready for configuration
. port ( 0 ) // Configures the port number as zero, this will let the system pick up
// an ephemeral port when binding the server
. route ( routes ->
// The server will respond only on POST requests
// where the path starts with /test and then there is path parameter
routes . post ( "/test/{param}" , ( request , response ) ->
response . sendString ( request . receive ()
. asString ()
. map ( s -> s + ' ' + request . param ( "param" ) + '!' )
. log ( "http-server" ))))
. bindNow (); // Starts the server in a blocking fashion, and waits for it to finish its initialization
HttpClient . create () // Prepares an HTTP client ready for configuration
. port ( server . port ()) // Obtains the server's port and provides it as a port to which this
// client should connect
. post () // Specifies that POST method will be used
. uri ( "/test/World" ) // Specifies the path
. send ( ByteBufFlux . fromString ( Flux . just ( "Hello" ))) // Sends the request body
. responseContent () // Receives the response body
. aggregate ()
. asString ()
. log ( "http-client" )
. block ();
使用Reactor Netty
時遇到問題?我們很樂意提供協助!
reactor-netty
標籤的問題。您也可以在 Gitter 上與社群聊天。Reactor Netty
的錯誤。Reactor Netty
使用GitHub's
整合問題追蹤系統來記錄錯誤和功能請求。如果您想提出問題,請遵循以下建議:
Reactor Netty
版本,以及您的Operating System
和JVM
版本。有關為Reactor Netty
做出貢獻的信息,請參閱我們的貢獻指南。
您不需要從原始碼建置來使用Reactor Netty
(repo.spring.io 中的二進位檔案),但如果您想嘗試最新且最好的,可以使用 gradle 包裝器輕鬆建置Reactor Netty
。您還需要 JDK 1.8。
$ git clone https://github.com/reactor/reactor-netty.git
$ cd reactor-netty
$ ./gradlew build
如果要將工件發佈到本機Maven
儲存庫,請使用:
$ ./gradlew publishToMavenLocal
https://projectreactor.io/docs/netty/release/api/
Reactor Netty
是在 Apache License 2.0 下發布的開源軟體