有没有办法使用Spring提供的工具来连接webSocket而不使用SockJS和STOMP?我需要实现专有的webSocket协议,所以我现在不能使用任何一个.
我已经从以下答案中实施/破解了解决方案,但它需要重新实现我认为我不应该担心的事情.
我想我的问题归结为:有没有办法让我使用2.(下面)的优点,特别是MessageBroker,而不使用STOMP?
一点背景:
我需要做以下事情:
到目前为止我尝试过的是:
即(伪代码)
@ServerEndpoint("/trade/{id}")
public String handleMessage(@PathParam(id) String id, webSocketSession session){
if(id.equalsIgnoreCase("foo"){
for(Session s: session.getOpenSessions(){
//do things}
} else if(id.equalsIgnoreCase("bar")){
//do other things
}
}
}
Run Code Online (Sandbox Code Playgroud)
@MessageMapping("/trade")和使用Spring websocket实现@SendTo("/queue/position-updates").这要求我至少使用STOMP.这意味着要破坏流程中的其他应用程序,这是我目前无法做到的.此外,还有我需要实施的专有协议的问题.即(伪代码)
@MessageMapping("/trade/{id}")
@SendTo("/trades/all")
public Greeting greeting(String message){
//do things, return message
}
Run Code Online (Sandbox Code Playgroud)
{id}从registry.addHandler(WebsocketHandlerPool(), "/trade/{id}")进WebsocketHandlerPool(),所以我有,当我创建每一个人来解析路径WebsocketHandler.理想情况下,我不想这样做.@MessageMapping和,我没有支持(据我所知)@SendTo.即(处理程序的伪代码:)
@Override
public void afterConnectionEstablished(WebSocketSession …Run Code Online (Sandbox Code Playgroud)