akka/akka-http

Access to websocket server materialized value

オープン

#1,167 opened on 2017/05/29

 (6 件のコメント) (3 件のリアクション) (0 人の担当者)Scala (598 件のフォーク)batch import
1 - triagedhelp wantedt:coret:servert:websocket

Repository metrics

Stars
 (1,311 個のスター)
PR merge metrics
 (平均マージ 1d 10h) (30d で 2 merged PRs)

説明

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)

コントリビューターガイド