3

Iv'e been using the following link in order to play with the new spring 4 websockets:

http://spring.io/guides/gs/messaging-stomp-websocket/

I was wondering if i must use a stomp broker in order to use the spring framework ? is there any broker less way to use it?

thanks

Urbanleg
  • 6,252
  • 16
  • 76
  • 139

2 Answers2

4

This guide is using the simple broker implementation provided in Spring Framework. It's just a piece of Java code that plays that part - there's no actual broker in that setup. So yes, there is a broker-less way to use this, and you're already doing it.

This implementation lacks many features though, and you may want to use a real broker (like RabbitMQ) in production.

Edit:

You don't have to use STOMP and a message broker, in fact you can use the Websocket API directly. As stated in this presentation:

Using a WebSocket API directly is a bit like writing a custom Servlet application, except the WebSocket protocol is on lower level than HTTP.

Depending on your app goals, you may go towards a message-driven application anyway; not an easy task to solve on your own...

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • Yes, I know, but is it possible to use the websocket with spring without ANY stomp broker? or Stomp is mandatory when you choose to use spring with websockets? – Urbanleg Apr 27 '14 at 07:04
  • @Urbanleg no its not mandatory its optional if you want to use stomp or not. Stomp is a higher level protocol so you don't need to deal with low level session handling stuff for websocket. – AliR May 27 '14 at 02:03
  • But what if I want to use stomp but don't provide a message broker? I would like to provide interface to handle stomp event myself instead of relying on the message broker – Phate May 26 '20 at 10:21
2

I would advise against using STOMP as it requires a framework to be embedded in your code. Frameworks come and go, and need to be updated.

You can use a Spring (boot) WebSocket channel to pass JSON without ever using STOMP. If you are talking with a front end application (e.g. JavaScript) the JSON is already your "model" data that can easily be passed/parsed bidirectionally.

The WebSocket API contains enough to be able to onConnect(), onMessage(), onError() your implementation. Actually I prefer this, because I am in control. For instance in the onConnect, you can validate tokens and customize security.

Coen Damen
  • 2,009
  • 5
  • 29
  • 51