The problem you are facing by default is clientInboundChannel , which is ExecutorSubscribableChannel by default.
It has 3 subscribers :
0 = { SimpleBrokerMessageHandler@5276 } "SimpleBroker[DefaultSubscriptionRegistry[cache[0 destination(s)], registry[0 sessions]]]" 1 = { UserDestinationMessageHandler@5277 } "UserDestinationMessageHandler[DefaultUserDestinationResolver[prefix=/user/]]" 2 = { SimpAnnotationMethodMessageHandler@5278 } "SimpAnnotationMethodMessageHandler[prefixes=[/app/]]"
which are called inside taskExecutor , therefore, asynchronously.
The first one here ( SimpleBrokerMessageHandler (or StompBrokerRelayMessageHandler ), if you use broker-relay ), is responsible for registering the subscription for topic .
Your operation messagingTemplate.convertAndSend(/topic/path, "msg") can be performed before registering a subscription for this WebSocket session, as they are executed in separate threads. Therefore, the broker handler does not know how to send a message to the session.
@SubscribeMapping can be configured using the return method, where the result of this method will be sent as a response to this subscription function on the client.
NTN
source share