Top Related Projects
Netty project - an event-driven asynchronous network application framework
Spring Framework
Vert.x is a tool-kit for building reactive applications on the JVM
Asynchronous Http and WebSocket Client library for Java
High performance non-blocking webserver
Quick Overview
Reactor Netty is a non-blocking and reactive network library built on top of Netty, designed for building efficient and scalable network applications. It provides a high-performance foundation for HTTP clients and servers, TCP clients and servers, and UDP clients and servers, all with a reactive programming model.
Pros
- High performance and scalability due to its non-blocking nature
- Seamless integration with the Reactor project ecosystem
- Supports both client and server implementations for HTTP, TCP, and UDP
- Offers backpressure-ready network operations
Cons
- Steep learning curve for developers new to reactive programming
- Debugging can be challenging due to the asynchronous nature of the library
- Limited documentation compared to more traditional networking libraries
- May be overkill for simple networking tasks
Code Examples
- Creating an HTTP server:
HttpServer.create()
.route(routes ->
routes.get("/hello", (request, response) -> response.sendString(Mono.just("Hello, World!")))
)
.bindNow()
.onDispose()
.block();
- Making an HTTP GET request:
HttpClient.create()
.get()
.uri("https://example.com")
.responseContent()
.aggregate()
.asString()
.block();
- Creating a TCP server:
TcpServer.create()
.handle((inbound, outbound) -> outbound.sendString(inbound.receive().asString()))
.bindNow()
.onDispose()
.block();
Getting Started
To use Reactor Netty in your project, add the following dependency to your Maven pom.xml
:
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>1.0.19</version>
</dependency>
Or for Gradle, add this to your build.gradle
:
implementation 'io.projectreactor.netty:reactor-netty:1.0.19'
Then, import the necessary classes in your Java code:
import reactor.netty.http.client.HttpClient;
import reactor.netty.http.server.HttpServer;
import reactor.netty.tcp.TcpServer;
You can now start using Reactor Netty to create reactive network applications.
Competitor Comparisons
Netty project - an event-driven asynchronous network application framework
Pros of Netty
- More mature and widely adopted project with a larger community
- Lower-level API offering finer control over network operations
- Supports a broader range of protocols and use cases
Cons of Netty
- Steeper learning curve due to its lower-level nature
- Requires more boilerplate code for common tasks
- Less integration with reactive programming paradigms
Code Comparison
Netty example:
EventLoopGroup group = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(group)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new EchoServerHandler());
}
});
Reactor Netty example:
HttpServer.create()
.host("localhost")
.port(8080)
.route(routes ->
routes.get("/hello",
(request, response) -> response.sendString(Mono.just("Hello, World!")))
)
.bindNow();
Reactor Netty builds upon Netty, providing a higher-level, reactive-friendly API. It simplifies common tasks and integrates well with Spring WebFlux. However, it may not offer the same level of fine-grained control as Netty for complex, custom network applications. The choice between the two depends on the specific requirements of your project and your familiarity with reactive programming concepts.
Spring Framework
Pros of Spring Framework
- Comprehensive ecosystem with extensive documentation and community support
- Provides a wide range of features for enterprise application development
- Integrates well with other Spring projects and third-party libraries
Cons of Spring Framework
- Steeper learning curve due to its extensive feature set
- Can be considered "heavyweight" for smaller applications
- Configuration can be complex, especially for beginners
Code Comparison
Spring Framework:
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
Reactor Netty:
HttpServer.create()
.route(routes ->
routes.get("/hello", (request, response) ->
response.sendString(Mono.just("Hello, World!"))))
.bindNow()
.onDispose()
.block();
Spring Framework offers a higher-level abstraction with annotations, while Reactor Netty provides a more low-level, reactive approach to building web applications. Spring Framework is better suited for large-scale enterprise applications, whereas Reactor Netty excels in building high-performance, reactive microservices.
Vert.x is a tool-kit for building reactive applications on the JVM
Pros of Vert.x
- More comprehensive toolkit with built-in support for various protocols and services
- Polyglot nature allows development in multiple programming languages
- Highly scalable and performant, especially for microservices architectures
Cons of Vert.x
- Steeper learning curve due to its broader scope and features
- Less focused on reactive programming compared to Reactor Netty
- May be overkill for simpler applications that only require basic networking capabilities
Code Comparison
Vert.x HTTP server:
Vertx vertx = Vertx.vertx();
vertx.createHttpServer().requestHandler(req -> {
req.response().end("Hello from Vert.x!");
}).listen(8080);
Reactor Netty HTTP server:
HttpServer.create()
.host("localhost")
.port(8080)
.route(routes -> routes.get("/", (req, res) -> res.sendString(Mono.just("Hello from Reactor Netty!"))))
.bindNow();
Both frameworks provide concise ways to create HTTP servers, but Vert.x offers a more straightforward approach for basic scenarios, while Reactor Netty's code style emphasizes its reactive nature.
Asynchronous Http and WebSocket Client library for Java
Pros of async-http-client
- Simpler API for basic HTTP requests
- Supports both synchronous and asynchronous operations
- Extensive documentation and examples available
Cons of async-http-client
- Less flexible for advanced networking scenarios
- Not built on top of Project Reactor, limiting reactive programming capabilities
- Fewer built-in features for WebSocket and server-sent events
Code Comparison
async-http-client:
AsyncHttpClient client = Dsl.asyncHttpClient();
Future<Response> f = client.prepareGet("http://www.example.com/").execute();
Response r = f.get();
reactor-netty:
HttpClient client = HttpClient.create();
Mono<String> response = client.get()
.uri("http://www.example.com/")
.responseContent()
.aggregate()
.asString();
reactor-netty offers a more reactive approach, leveraging Project Reactor's Mono
and Flux
types for composable asynchronous operations. It provides better integration with the Spring ecosystem and supports advanced networking features like HTTP/2 and WebSockets out of the box.
async-http-client, on the other hand, offers a more straightforward API for simple HTTP requests and may be easier to adopt for developers not familiar with reactive programming concepts. However, it lacks some of the advanced features and flexibility provided by reactor-netty.
Both libraries are actively maintained and have their own strengths, so the choice between them depends on specific project requirements and the development team's familiarity with reactive programming concepts.
High performance non-blocking webserver
Pros of Undertow
- Lightweight and highly performant web server
- Supports both blocking and non-blocking APIs
- Excellent integration with Jakarta EE and MicroProfile
Cons of Undertow
- Less active community and fewer updates compared to Reactor Netty
- Limited built-in support for reactive programming patterns
- Steeper learning curve for developers new to the Undertow ecosystem
Code Comparison
Undertow server setup:
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(exchange -> {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello, World!");
}).build();
server.start();
Reactor Netty server setup:
HttpServer.create()
.port(8080)
.route(routes ->
routes.get("/",
(request, response) -> response.sendString(Mono.just("Hello, World!"))))
.bindNow()
.onDispose()
.block();
Both Undertow and Reactor Netty are powerful web server frameworks, but they cater to different use cases. Undertow excels in traditional web server scenarios and Jakarta EE environments, while Reactor Netty is better suited for reactive and non-blocking applications. The choice between them depends on the specific requirements of your project and your team's expertise.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Reactor Netty
Reactor Netty
offers non-blocking and backpressure-ready TCP
/HTTP
/UDP
/QUIC
clients & servers based on Netty
framework.
Getting it
Reactor Netty
requires Java 8 or + to run.
With Gradle
from repo.spring.io or Maven Central
repositories (stable releases only):
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.0-SNAPSHOT"
compile "io.projectreactor.netty:reactor-netty-core:1.2.0-M5"
//compile "io.projectreactor.netty:reactor-netty-http:1.2.0-SNAPSHOT"
compile "io.projectreactor.netty:reactor-netty-http:1.2.0-M5"
}
See the Reference documentation
for more information on getting it (eg. using Maven
, or on how to get milestones and snapshots).
Getting Started
New to Reactor Netty
? Check this Reactor Netty Workshop
and the Reference documentation
Here is a very simple HTTP
server and the corresponding HTTP
client example
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();
Getting help
Having trouble with Reactor Netty
? We'd like to help!
- If you are upgrading, read the release notes for upgrade instructions and new and noteworthy features.
- Ask a question - we monitor stackoverflow.com for questions
tagged with
reactor-netty
. You can also chat with the community on Gitter. - Report bugs with
Reactor Netty
at github.com/reactor/reactor-netty/issues. - More about Support and Deprecation policies
Reporting Issues
Reactor Netty
uses GitHubâs
integrated issue tracking system to record bugs and feature requests.
If you want to raise an issue, please follow the recommendations below:
- Before you log a bug, please search the issue tracker to see if someone has already reported the problem.
- If the issue doesn't already exist, create a new issue.
- Please provide as much information as possible with the issue report, we like to know
the version of
Reactor Netty
that you are using, as well as yourOperating System
andJVM
version. - If you want to raise a security vulnerability, please review our Security Policy for more details.
Contributing
See our Contributing Guide for information about contributing to Reactor Netty
.
Building from Source
You don't need to build from source to use Reactor Netty
(binaries in
repo.spring.io), but if you want to try out the latest and
greatest, Reactor Netty
can be easily built with the
gradle wrapper. You also need JDK 1.8.
$ git clone https://github.com/reactor/reactor-netty.git
$ cd reactor-netty
$ ./gradlew build
If you want to publish the artifacts to your local Maven
repository use:
$ ./gradlew publishToMavenLocal
Javadoc
https://projectreactor.io/docs/netty/release/api/
Guides
- https://projectreactor.io/docs/netty/release/reference/index.html
- https://violetagg.github.io/reactor-netty-workshop/
License
Reactor Netty
is Open Source Software released under the Apache License 2.0
Top Related Projects
Netty project - an event-driven asynchronous network application framework
Spring Framework
Vert.x is a tool-kit for building reactive applications on the JVM
Asynchronous Http and WebSocket Client library for Java
High performance non-blocking webserver
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot