• Stars
    star
    111
  • Rank 303,620 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reactive streams implementation for Netty.

Netty Reactive Streams

Twitter Follow Discord GitHub Discussions StackOverflow YouTube Twitch Status OpenCollective

Build Status Maven Repository size

This provides a reactive streams implementation for Netty. Essentially it comes in the form of two channel handlers, one that publishes inbound messages received on a channel to a Publisher, and another that writes messages received by a Subscriber outbound.

Features include:

  • Full backpressure support, as long as the AUTO_READ channel option is disabled.
  • Publishers/subscribers can be dynamically added and removed from the pipeline.
  • Multiple publishers/subscribers can be inserted into the pipeline.
  • Customisable cancel/complete/failure handling.

Releasing a new version

This project is released and published through Sonatype. You must have Sonatype credentials installed, preferably in $HOME/.m2/settings.xml and a GPG key that is available to the standard GPG keyservers. If your key is not on the server, you should add it to the keyserver as follows:

gpg --send-key <MY_KEYID> --keyserver pgp.mit.edu

After that, you can perform a release through the following commands:

mvn release:prepare -Darguments=-Dgpg.passphrase=thephrase
mvn release:perform -Darguments=-Dgpg.passphrase=thephrase

This will push a release to the staging repository and automatically close and publish the staging repository to production.

Using the publisher/subscriber

Here's an example of creating a client channel that publishes/subscribes to ByteBuf's:

EventLoopGroup workerGroup = new NioEventLoopGroup();

Bootstrap bootstrap = new Bootstrap()
  .group(workerGroup)
  .channel(NioSocketChannel.class)
  .option(ChannelOption.SO_KEEPALIVE, true);
  .handler(new ChannelInitializer<SocketChannel>() {
    @Override
    public void initChannel(SocketChannel ch) throws Exception {
      HandlerPublisher<ByteBuf> publisher = new HandlerPublisher<>(ch.executor(),
        ByteBuf.class);
      HandlerSubscriber<ByteBuf> subscriber = new HandlerSubscriber<>(ch.executor());

      // Here you can subscriber to the publisher, and pass the subscriber to a publisher.

      ch.pipeline().addLast(publisher, subscriber);
    }
});

Notice that the channels executor is explicitly passed to the publisher and subscriber constructors. HandlerPublisher and HandlerSubscriber use Netty's happens before guarantees made by its EventExecutor interface in order to handle asynchronous events from reactive streams, hence they need to have an executor to do this with. This executor must also be the same executor that the handler is registered to use with the channel, so that all channel events are fired from the same context. The publisher/subscriber will throw an exception if the handler is registered with a different executor.

A word of caution with ByteBuf's

Reactive streams allows implementations to drop messages when a stream is cancelled or failed - Netty reactive streams does this itself. This introduces a problem when those messages hold resources and must be cleaned up, for example, if they are ByteBuf's that need to be released. While Netty reactive streams will call ReferenceCountUtil.release() on every message that it drops, other implementations that it's interacting with likely won't do this.

For this reason, you should make sure you do one of the following:

  • Insert a handler in the pipeline that converts incoming ByteBuf's to some non reference counted structure, for example byte[], or some high level immutable message structure, and have the HandlerPublisher publish those. Similarly, the HandlerSubscriber should subscribe to some non reference counted structure, and a handler should be placed in the pipeline to convert these structures to ByteBuf's.
  • Write a wrapping Publisher and Subscriber that synchronously converts ByteBuf's to/from a non reference counted structure.

Netty Reactive Streams HTTP

In addition to raw reactive streams support, the netty-reactive-streams-http library provides some HTTP model abstractions and a handle for implementing HTTP servers/clients that use reactive streams to stream HTTP message bodies. The HttpStreamsServerHandler and HttpStreamsClientHandler ensure that every HttpRequest and HttpResponse in the pipeline is either a FullHttpRequest or FullHttpResponse, for when the body can be worked with in memory, or StreamedHttpRequest or StreamedHttpResponse, which are messages that double as Publisher<HttpContent> for handling the request/response body.

More Repositories

1

playframework

The Community Maintained High Velocity Web Framework For Java and Scala.
Scala
12,479
star
2

play1

Play framework
Java
1,578
star
3

play-slick

Slick Plugin for Play
Scala
799
star
4

twirl

Twirl is Play's default template engine
Scala
535
star
5

play-samples

Play Framework Sample Projects
JavaScript
501
star
6

play-plugins

CachePlugin
JavaScript
444
star
7

play-json

The Play JSON library
Scala
354
star
8

play-mailer

Play mailer plugin
Scala
249
star
9

play-scala-starter-example

Play Scala Starter Template (ideal for new users!)
CSS
235
star
10

anorm

The Anorm database library
Scala
233
star
11

play-ws

Standalone Play WS, an async HTTP client with fluent API
Scala
220
star
12

play-scala-rest-api-example

Example Play Scala application showing REST API
Scala
212
star
13

play-scala-react-seed

❄️ Scala Play + React seed project with full-fledged build process
Shell
200
star
14

play-scala-websocket-example

Example Play Scala application showing WebSocket use with Akka actors
Scala
194
star
15

play-java-starter-example

Play starter project in Java (ideal for new users!)
CSS
160
star
16

play-scala-isolated-slick-example

Example Play Slick Project
Scala
154
star
17

scalatestplus-play

ScalaTest + Play
Scala
104
star
18

play-ebean

Play Ebean module
Java
100
star
19

play-socket.io

Play socket.io support
Scala
92
star
20

play-java-websocket-example

Example Play Java application showing Websocket usage with Akka actors
Java
88
star
21

play-scala-angular-seed

πŸ€ Scala Play 2.7.x + Angular 8 with Angular CLI seed project with full-fledged build process
TypeScript
85
star
22

prune

Performance testing tool for Play Framework
Scala
80
star
23

play-scala-seed.g8

Play Scala Seed Template: run "sbt new playframework/play-scala-seed.g8"
Scala
70
star
24

play-silhouette

Silhouette is an authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, CAS, 2FA, TOTP, Credentials, Basic Authentication or custom authentication schemes.
Scala
68
star
25

play-scala-slick-example

Example Play Scala project with Slick
Scala
59
star
26

modules.playframework.org

Java
56
star
27

play-scala-secure-session-example

An example Play application showing encrypted session management
Scala
56
star
28

play-java-ebean-example

Example Play application showing Java with Ebean
Java
53
star
29

play-java-angular-seed

🍁 Java Play 2.7.x + Angular 8 with Angular CLI seed project with full-fledged build process
TypeScript
52
star
30

play-scala-macwire-di-example

Sample project for compile-time DI with Macwire
Scala
47
star
31

playframework.com

The Play Framework website
Scala
44
star
32

play-java-rest-api-example

REST API using Play in Java
Java
44
star
33

play-scala-chatroom-example

Play chatroom with Scala API
Scala
43
star
34

play-scala-tls-example

A Play application using HTTPS and WS with optional client authentication
Scala
43
star
35

play-java-react-seed

πŸŒ€ Java Play 2.7.x + React seed project with full-fledged build process
Shell
43
star
36

play-scala-streaming-example

Example Play application showing Comet and Server Sent Events in Scala
Scala
42
star
37

play-scala-anorm-example

Example Play Database Application using Anorm
Scala
40
star
38

play-java-dagger2-example

Play Application using Dagger 2 for Compile Time DI
Java
38
star
39

play-scala-compile-di-example

Example Play Project using compile time dependency injection and Play WS with ScalaTest
Scala
37
star
40

play-soap

Play SOAP support
Scala
34
star
41

play-grpc

Play + Akka gRPC
Scala
34
star
42

play-java-jpa-example

Example Play Java project with JPA database integration
Java
34
star
43

play-java-chatroom-example

Example Chatroom with Java API
Java
33
star
44

play-scala-fileupload-example

An example Play application showing custom multiform fileupload in Scala
Scala
28
star
45

play-java-seed.g8

Play Java Seed template: use "sbt new playframework/play-java-seed.g8"
Java
21
star
46

play-doc

Play documentation rendering support
Scala
20
star
47

play-webgoat

A vulnerable Play application for attackers.
Scala
17
star
48

play-iteratees

Scala
17
star
49

play-scala-forms-example

Example Play Project showing form processing
Scala
15
star
50

play-glassfish

Play container for Glassfish
Java
15
star
51

cachecontrol

Minimal HTTP cache management library in Scala
Scala
13
star
52

play-scala-log4j2-example

An example Play project using Log4J 2 as the logging engine
Scala
13
star
53

play-enhancer

Java
13
star
54

play-java-fileupload-example

An example Play application showing custom multiform fileupload in Java
Java
13
star
55

play-file-watch

This is the Play File Watch library
Java
12
star
56

interplay

Common sbt plugins for Play modules
Scala
11
star
57

play-generated-docs

Generated docs for publishing to the Play website.
10
star
58

play-scala-hello-world-tutorial

Hello World Tutorial for Play in Scala
HTML
9
star
59

play-spring-loader

An application loader for Play that uses Spring as the dependency injection framework
Scala
9
star
60

play-java-streaming-example

Example Play application showing Comet and Server Sent Events in Java
JavaScript
8
star
61

play-scala-grpc-example

Example for akka-grpc services embedded in Play framework applications (Scala)
CSS
8
star
62

play-meta

Team management & cross-repository effort tracking
Shell
7
star
63

play-java-hello-world-tutorial

Play Hello World tutorial in Java
HTML
5
star
64

omnidoc

Play aggregated documentation
Scala
5
star
65

.github

Scala
4
star
66

play-java-forms-example

Play Project Template showing Java Forms Processing
Java
4
star
67

play-java-compile-di-example

Example Play application using compile time DI with Java API
Java
3
star
68

play-java-grpc-example

Example for akka-grpc services embedded in Play framework applications (Java)
CSS
3
star
69

templatecontrol

Template Control for Play templates and other examples
Scala
3
star
70

play-quota-scala-example

An example of User Quotas using Play and Scala
Scala
2
star
71

modules.playframework.com

The Play Framework module index
Scala
2
star
72

play-native-loader

Loading native libraries in Play Framework
Java
2
star
73

play-quota-java-example

An example application using Play Quota with Java API
Java
2
star
74

playframework.github.io

1
star
75

jnotify

Scala
1
star