From 2fc76e657a56b0fd201a20346681e5116b9037e2 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 25 Apr 2025 14:43:27 +0300 Subject: [PATCH] Provide a working example instead of unclear placeholders Signed-off-by: Artur --- .../web/reactive/socket/WebSocketHandler.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketHandler.java index 0703dae330d4..ab6c8aa2eca1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketHandler.java @@ -45,13 +45,26 @@ * public Mono<Void> handle(WebSocketSession session) { * * Flux<WebSocketMessage> output = session.receive() - * .doOnNext(message -> { - * // ... + * .doOnNext(message -> { + * // This is for side effects such as + * // - Logging incoming messages + * // - Updating some metrics or counters + * // - Performing access checks or validations (non-blocking) + * System.out.println("Got message: " + message.getPayloadAsText()); * }) * .concatMap(message -> { - * // ... + * // This is where you handle the actual processing of the incoming message. It + * // might involve: + * // - Parsing the message content (e.g., JSON parsing) + * // - Invoking a reactive service (e.g., database, HTTP call, etc.) + * // - Returning a transformed value, typically a Mono<String> or Mono<SomeType> + * // if you're mapping to another data format + * return Mono.just(message.getPayloadAsText()); * }) - * .map(value -> session.textMessage("Echo " + value)); + * .map(value -> { + * // This is where you produce one or more responses for the message + * return session.textMessage("Echo " + value)); + * }); * * return session.send(output); * }