添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to enable sockets in a Spring application and in the documentation came up 2 ways of using them, plain and with STOMP enabled.

I understand that the later is backed up by a message broker but did not find any good explanation of this feature.

So, my question would be, what does Spring bring in the back scenes when @EnableWebSocketMessageBroker is used, compared to @EnableWebSocket ?

You already stated the differences yourself. The @EnableWebSocket enables plain websockets, if you want to use stomp you need a broker and need to the @EnableWebSocketMessageBroker to indicate this. M. Deinum Jul 23, 2018 at 8:51 Thanks Deinum for the quick comment. I was wondering if there is any documentation that describes this better. Would an application work as-is if the EnableWebSocket is switched to EnableWebSocketMessageBroker ? Put it other way, I wanted to read about this in more depth and did not find articles other than tutorials. Victor Jul 24, 2018 at 7:39

From what I have read so far, the difference consists in the fact that the later ( @EnableWebSocketMessageBroker ) offers a better handling for the exchanged messages. In order to keep them somehow in controll, a very good approach is to use a message broker:

  • easy to broadcast to intersted parts. Otherwise you have to keep trace of session and to iterate through them in order to send a message to each client who is interested
  • assuring the message got to the client. Out of the box, a message broker offers acknowledgement flags that will be interchanged between client and server in order to assure the message transmission and interception
  • Note : the annotation @EnableWebSocketMessageBroker does not by default add an underlying full-featured Broker, but a "Simple one". The simple version:

  • supports subset of STOMP: SUBSCRIBE, UNSUBSCRIBE, MESSAGE
  • no acks, receipts, transactions
  • simple message sending loop
  • not suitable for clustering
  • A full-featured one will add more functionalities, that can be found on its presentation documentation. (read more in http://rstoyanchev.github.io/s2gx2013-websocket-browser-apps-with-spring )

    Other nice to read reference: Message queues vs sockets , The MessageBroker WebSocket Subprotocol

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .