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

我怕爱的太早我们不能终老 提交于 2020-02-25 05:50:09

问题


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


回答1:


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




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



来源:https://stackoverflow.com/questions/23275227/spring-4-web-sockets-do-i-must-have-a-stomp-broker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!