jakartaee / jakartaee/websocket
Reactive Streams Support
- Dominant language
- Java
- Stars
- 78
- Forks
- 47
- Avg merge
- 1h 32m
- Merged PRs (30d)
- 1
Description
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:
```java
private Flow.Subscriber createKafkaSubscriber(String room) {
// Kafka specific code to create subscriber for consuming messages to send to Kafka
...
}
private Flow.Publisher createKafkaPublisher(String room) {
// Kafka specific code to create publisher for producing messages received from Kafka
...
}
@OnStream
public Flow.Publisher connectToRoom(
@PathParam("room") String room,
Flow.Publisher 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.
Contributor guide
Research direction
The issue names no repository files or tests to use as an entry point. Start by reviewing the existing WebSocket specification and the JDK9 Flow API, then compare the connectToRoom example with current message-handling behavior. Done would require a decided design and WebSocket support for publishers, subscribers, backpressure, errors, and completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kafka
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100