Spriing WebFlux WebSocket Handler Mapping and Replacing path for messages

21 Views Asked by At

i want to know does anybody know how can i achive of makeing a universal bath based on path variable for websocket, also i would like to know how could i handle message sending to specific url in websocket since handle method doesnt support chaning path of message, thanks!

` @Override public Mono handle(WebSocketSession webSocketSession) {

    Flux<String> receivedMessages = webSocketSession.receive()
                                                .map(WebSocketMessage::getPayloadAsText);


    Flux<WebSocketMessage> webSocketMessage = receivedMessages.flatMap(message -> {
            try {
                return saveCommentMessageAndConvertToJson(message)
                        .map(jsonCommentDto -> {
                            return webSocketSession.textMessage(jsonCommentDto);
                        });
            } catch (JsonProcessingException e) {
                return Mono.empty();
            }
        });

    return  webSocketSession.send(webSocketMessage).;
}`

this is what i have tried but i doesnt get any idea on how i would achive that, also i was looking stack,forums,docs nothing helps me out about this problem..

0

There are 0 best solutions below