Skip to content

Commit bd70072

Browse files
Artur-rstoyanchev
authored andcommitted
Provide a working example instead of unclear placeholders
See gh-34828 Signed-off-by: Artur <[email protected]>
1 parent e8f873a commit bd70072

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketHandler.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,26 @@
4545
* public Mono&lt;Void&gt; handle(WebSocketSession session) {
4646
*
4747
* Flux&lt;WebSocketMessage&gt; output = session.receive()
48-
* .doOnNext(message -&gt; {
49-
* // ...
48+
* .doOnNext(message -&gt; {
49+
* // This is for side effects such as
50+
* // - Logging incoming messages
51+
* // - Updating some metrics or counters
52+
* // - Performing access checks or validations (non-blocking)
53+
* System.out.println("Got message: " + message.getPayloadAsText());
5054
* })
5155
* .concatMap(message -&gt; {
52-
* // ...
56+
* // This is where you handle the actual processing of the incoming message. It
57+
* // might involve:
58+
* // - Parsing the message content (e.g., JSON parsing)
59+
* // - Invoking a reactive service (e.g., database, HTTP call, etc.)
60+
* // - Returning a transformed value, typically a Mono&lt;String&gt; or Mono&lt;SomeType&gt;
61+
* // if you're mapping to another data format
62+
* return Mono.just(message.getPayloadAsText());
5363
* })
54-
* .map(value -&gt; session.textMessage("Echo " + value));
64+
* .map(value -&gt; {
65+
* // This is where you produce one or more responses for the message
66+
* return session.textMessage("Echo " + value));
67+
* });
5568
*
5669
* return session.send(output);
5770
* }

0 commit comments

Comments
 (0)