Is there a way to use the tools provided by Spring to connect to webSocket without using SockJS and STOMP? I need to implement the proprietary webSocket protocol, so I cannot use any of them at the moment.
I implemented / hacked the solution from the following answer , but it requires me to redefine things that I feel I should not worry about.
I think my question boils down to: is there a way to use nice features 2.(below), in particular MessageBroker, without using STOMP?
A bit of background:
I need to do the following:
- Be able to embed a link to my persistence provider in each instance of the websocket handler
- Handle each webSocket session in a separate instance of my handler object.
- Resubmit the messages that I receive at one endpoint to multiple clients on another endpoint.
- Implement your own protocol through a standard Text WebSocket connection.
I have tried so far:
- Use javax.websocket where I can process each request in a separate instance. However, I need to iterate over open sessions and retransmit those that are associated with the correct endpoint. Also, I cannot use Spring to enter my continuity provider. This is what I have used so far, and it seems to be too hacked.
those. (Pseudo code)
@ServerEndpoint("/trade/{id}")
public String handleMessage(@PathParam(id) String id, webSocketSession session){
if(id.equalsIgnoreCase("foo"){
for(Session s: session.getOpenSessions(){
} else if(id.equalsIgnoreCase("bar")){
}
}
}
- websocket Spring
@MessageMapping("/trade") @SendTo("/queue/position-updates"). , , STOMP. , . , , .
.. (-)
@MessageMapping("/trade/{id}")
@SendTo("/trades/all")
public Greeting greeting(String message){
}
- websocket Spring, WebSocketConfigurer . . , Spring:
{id} registry.addHandler(WebsocketHandlerPool(), "/trade/{id}") WebsocketHandlerPool(), , WebsocketHandler. .- , websocket. ( )
@MessageMapping @SendTo.
.. ( :)
@Override
public void afterConnectionEstablished(WebSocketSession s){
idFromSessionPath = getIdFromSessionPath(s);
}
@Override
public String handleTextMessage(WebSocketSession session, TextMessage message
{
If(idFromSessionPath.equals("foo"){
} else {
}
}
( )
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry){
registry.addHandler(threadPool(), "/trade/{id}");
}
@Bean
public WebSocketHandler threadPool(){
return new PerConnectionWebSocketHandler(TradeStreamingHandler.class);
}