Urbanleg
Urbanleg

Reputation: 6532

Spring 4 Web sockets - Do i must have a stomp broker?

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

Upvotes: 4

Views: 5381

Answers (2)

Coen Damen
Coen Damen

Reputation: 2109

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.

Upvotes: 3

Brian Clozel
Brian Clozel

Reputation: 59086

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...

Upvotes: 5

Related Questions