Description
Websocket server methods do not allow accessing the materialized value of the flow it is given. They take a flow as argument and return the HTTP response to send back:
HttpResponse response = WebSocket.handleWebSocketRequestWith(request, greeterFlow);
The server takes care of materializing the flow and ignores both values. This prevents users from getting them, which can be problematic. For example if the flow source is a queue, one needs to get its materialized value in order to push to the queue. A workaround is to setup a callback on mapMaterializedValue to send the queue to whoever is interested in it:
Source.<Message>queue(5, OverflowStrategy.backpressure())
.mapMaterializedValue(sourceQueue -> { /* send queue to whoever is interested */; return sourceQueue; });
But this is a workaround rather than a clean solution, as mapMaterializedValue is meant to transform the materialized value rather than broadcast it. The client has methods that return this materialized value:
Pair<CompletionStage<WebSocketUpgradeResponse>, SourceQueueWithComplete<Message>> pair =
http.singleWebSocketRequest(WebSocketRequest.create(connect), flow, materializer);
It would be great if the server had methods for doing something similar. This might be tricky since contrary to the client, the server takes care of materializing the value after the response it sent.
(mailing list pointer: Graph materialized value of websocket upgrade)