Update STOMP section on working with subscriptions
1. Revise @SubscribeMapping to address common points of confusion.
2. Add ExecutorSubsribableChannel.
3. Split Events and Interception in two.
Issue: SPR-16950
A server side option is <<websocket-stomp-interceptors,to register>> an
`ExecutorChannelInterceptor` on the `brokerChannel` and implement the `afterMessageHandled`
method that is invoked after messages, including subscriptions, have been handled.
[[websocket-stomp-exception-handler]]
@ -1968,9 +2003,8 @@ Note that this incurs a small performance overhead, so enable it only if require
@@ -1968,9 +2003,8 @@ Note that this incurs a small performance overhead, so enable it only if require
[[websocket-stomp-appplication-context-events]]
=== Events and Interception
=== Events
Several `ApplicationContext` events (listed below) are published and can be
received by implementing Spring's `ApplicationListener` interface.
@ -2010,10 +2044,15 @@ will typically notice the broker is not responding within 10 seconds. Clients ne
@@ -2010,10 +2044,15 @@ will typically notice the broker is not responding within 10 seconds. Clients ne
implement their own reconnect logic.
====
The above events reflect points in the lifecycle of a STOMP connection. They're not meant
to provide notification for every message sent from the client. Instead an application
can register a `ChannelInterceptor` to intercept every incoming and outgoing STOMP message.
For example to intercept inbound messages:
[[websocket-stomp-interceptors]]
=== Interception
<<websocket-stomp-appplication-context-events>> provide notifications for the lifecycle
of a STOMP connection and not for every client message. Applications can also register a
`ChannelInterceptor` to intercept any message, and in any part of the processing chain.
For example to intercept inbound messages from clients:
[source,java,indent=0]
[subs="verbatim,quotes"]
@ -2035,7 +2074,7 @@ to access information about the message.
@@ -2035,7 +2074,7 @@ to access information about the message.
[source,java,indent=0]
[subs="verbatim,quotes"]
----
public class MyChannelInterceptor extends ChannelInterceptorAdapter {
public class MyChannelInterceptor implements ChannelInterceptor {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
@ -2047,6 +2086,12 @@ to access information about the message.
@@ -2047,6 +2086,12 @@ to access information about the message.
}
----
Applications may also implement `ExecutorChannelInterceptor` which is a sub-interface
of `ChannelInterceptor` with callbacks in the thread in which the messages are handled.
While a `ChannelInterceptor` is invoked once for per message sent to a channel, the
`ExecutorChannelInterceptor` provides hooks in the thread of each `MessageHandler`
subscribed to messages from the channel.
Note that just like with the `SesionDisconnectEvent` above, a DISCONNECT message
may have been sent from the client, or it may also be automatically generated when
the WebSocket session is closed. In some cases an interceptor may intercept this