akka/akka-http

Access to websocket server materialized value

Aberta

#1.167 aberto em 29 de mai. de 2017

 (6 comentários) (3 reações) (0 responsável)Scala (598 forks)batch import
1 - triagedhelp wantedt:coret:servert:websocket

Métricas do repositório

Stars
 (1.311 estrelas)
Métricas de merge de PR
 (Mesclagem média 1d 10h) (2 fundiu PRs em 30d)

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)

Guia do colaborador