@@ -1292,26 +1292,18 @@ handled under the covers. See <<websocket-stomp-handle-send>>.
1292
1292
[[websocket-stomp-subscribe-mapping]]
1293
1293
==== `@SubscribeMapping`
1294
1294
1295
- The `@SubscribeMapping` annotation is used in combination with `@MessageMapping` in order
1296
- to narrow the mapping to subscription messages. In such scenarios, the `@MessageMapping`
1297
- annotation specifies the destination while `@SubscribeMapping` indicates interest in
1298
- subscription messages only.
1299
-
1300
- An `@SubscribeMapping` method is generally no different from any `@MessageMapping`
1301
- method with respect to mapping and input arguments. For example you can combine it with a
1302
- type-level `@MessageMapping` to express a shared destination prefix, and you can use the
1303
- same <<websocket-stomp-message-mapping,method arguments>> as any @MessageMapping` method.
1304
-
1305
- The key difference with `@SubscribeMapping` is that the return value of the method is
1306
- serialized as a payload and sent, not to the "brokerChannel" but to the
1307
- "clientOutboundChannel", effectively replying directly to the client rather than
1308
- broadcasting through the broker. This is useful for implementing one-off, request-reply
1309
- message exchanges, and never holding on to the subscription. A common scenario for this
1310
- pattern is application initialization when data must be loaded and presented.
1311
-
1312
- A `@SubscribeMapping` method can also be annotated with `@SendTo` in which case the
1313
- return value is sent to the `"brokerChannel"` with the explicitly specified target
1314
- destination.
1295
+ `@SubscribeMapping` is similar to `@MessageMapping` but also narrows the mapping to
1296
+ subscription messages only. Methods with `@SubscribeMapping` support the same
1297
+ <<websocket-stomp-message-mapping,method arguments>> as `@MessageMapping` methods do.
1298
+ The main difference is that for the return value, in the absence of `@SendTo` and
1299
+ `@SendToUser`, a message is sent directly as a reply to the subscription, via the
1300
+ "clientOutboundChannel" channel. Effectively in this case the subscription is used as
1301
+ a one-time, request-reply message exchange with the subscription never stored.
1302
+ This is useful for loading data on startup and for initializing a front-end UI.
1303
+
1304
+ If an `@SubscribeMapping` method is annotated with `@SendTo` or `@SendToUser` the return
1305
+ value is sent to the `"brokerChannel"` as usual, i.e. sending a message to subscribers
1306
+ of the specified destination(s).
1315
1307
1316
1308
1317
1309
[[websocket-stomp-exception-handler]]
0 commit comments