Difference between /topic, /queue for SimpleMessageBroker in Spring Websocket + SockJS

You should take a look at this part of the reference documentation. In a nutshell, "/topic" and "/queue" are both prefixes configured to the same destination.

In the documentation, "/app" is the configured "application destination prefix" - meaning all messages flowing in through the "clientInboundChannel" and matching those prefixes will be mapped to your application, for example with @MessageMapping annotations.

Here also, "/topic" and "/queue" are both prefixes configured as STOMP destinations - meaning all messages flowing in through the "clientInboundChannel" and matching those prefixes will be forwarded to the STOMP broker. In your case, that's the simple broker implementation.

So from Spring Websocket's point of view, "/queue" and "/topic" are treated the same way and are "typical" STOMP destinations - all messages matching those are forwarded to the messages broker. Now if you're using a full message broker implementation, those destinations may not have the same meaning and the message broker behavior could be different. Here are some examples with Apache Apollo and RabbitMQ.

Note that if you want to, you can change those prefixes. But I would advise you to keep those as defaults unless you really know what you're doing.


I think the best answer for that topic would be the following from Spring Docs

The meaning of a destination is intentionally left opaque in the STOMP spec. It can be any string, and it’s entirely up to STOMP servers to define the semantics and the syntax of the destinations that they support. It is very common, however, for destinations to be path-like strings where "/topic/.." implies publish-subscribe (one-to-many) and "/queue/" implies point-to-point (one-to-one) message exchanges.


There is a bigger and more important difference not mentioned in the answers above.

Topic is auto-delete whereas queue is durable. It means that when the websocket connection is closed, the topic and its data is removed. in queue, the server can still send messages and when client connect via websocket, it receives old sent messages by server.

By the way, there is no difference in in-memory broker. This happens when using dedicated broker.