Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive Streams Support #244

Open
glassfishrobot opened this issue Jan 3, 2018 · 1 comment
Open

Reactive Streams Support #244

glassfishrobot opened this issue Jan 3, 2018 · 1 comment
Labels
API (Both) Impacts the client and server API enhancement Adding a new feature or improving an existing one
Milestone

Comments

@glassfishrobot
Copy link

Reactive Streams, also known as the JDK9 juc.Flow API, allows developers to plumb asynchronous streams of messages between libraries, in a way that safely ensures that backpressure, error and completion handling are correctly propagated through the streams. Providing support for Reactive Streams in the WebSocket spec would allow JSR356 WebSocket implementations to participate in this rich and growing ecosystem of asynchronous streaming libraries.

Use cases include plumbing WebSocket connections together, plumbing message broker subscribers and publishers into WebSocket streams, and integration with dedicated streaming libraries such as Akka, Reactor and RxJava, to allow developers to create complex graphs of streams.

As an example of what reactive streams support could look like, here's what it might look like to build a chat room using Kafka (using a Kafka reactive streams client such as https://github.com/unicredit/kafka-reactive-streams) as the backend for publishing and subscribing to messages:

private Flow.Subscriber<ChatMessage> createKafkaSubscriber(String room) {
  // Kafka specific code to create subscriber for consuming messages to send to Kafka
  ...
}

private Flow.Publisher<ChatMessage> createKafkaPublisher(String room) {
  // Kafka specific code to create publisher for producing messages received from Kafka
  ...
}

@OnStream
public Flow.Publisher<ChatMessage> connectToRoom(
    @PathParam("room") String room,
    Flow.Publisher<ChatMessage> incomingMessages) {
  incomingMessages.subscribe(createKafkaSubscriber(room));
  return createKafkaPublisher(room);
}

All the WebSocket specific code relating to plumbing messages, back pressure, and stream error handling can be seen in the connectToRoom method, which is invoked when the WebSocket is connected. The passed in incomingMessages publisher is the incoming WebSocket stream, each message being a chat message to publish to the room, while the returned Publisher is a stream of all the messages published to the chat room.

@glassfishrobot
Copy link
Author

@markt-asf markt-asf added API (Both) Impacts the client and server API enhancement Adding a new feature or improving an existing one Jakarta EE 10 labels Apr 16, 2020
@markt-asf markt-asf added this to the backlog milestone May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API (Both) Impacts the client and server API enhancement Adding a new feature or improving an existing one
Projects
None yet
Development

No branches or pull requests

2 participants