Video in progress

Why is the client not receiving any messages with this STOMP setup?

registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/topic");

@MessageMapping("/news.publish")
@SendTo("/topic/news")
public News publish(News n) { return n; }
client.subscribe('/app/news', msg => show(msg.body));
client.publish({ destination: '/app/news.publish', body: JSON.stringify(n) });

The client subscribed to /app/news, but /app is the prefix for sending messages to controllers, and the broker distributes nothing there. The subscription has to go to the destination in @SendTo, which is /topic/news.

📖 Answer

The message path:

  1. SEND /app/news.publish → the controller method runs (this part is correct).
  2. The result goes to /topic/news → the simple broker looks for subscribers of that destination.
  3. Nobody is subscribed to /topic/news, so the message is silently dropped.

No error appears, which is why this bug takes a long time to find.

The correct version:

client.subscribe('/topic/news', msg => show(msg.body));

The interesting part: SUBSCRIBE to /app/... isn't meaningless either. Spring has @SubscribeMapping("/news"). It runs once when a client subscribes to /app/news and returns the reply directly to that client, not through the broker. This is handy for loading the initial state (say, the last 20 news items). Later updates still arrive through /topic.

To debug, turn on logging.level.org.springframework.messaging=DEBUG, which shows what went to which destination.