Path variables in Spring WebSockets @SendTo mapping

前端 未结 3 2016
暖寄归人
暖寄归人 2020-12-02 10:02

I have, what I think to be, a very simple Spring WebSocket application. However, I\'m trying to use path variables for the subscription as well as the message mapping.

3条回答
  •  没有蜡笔的小新
    2020-12-02 10:23

    you can send a variable inside the path. for example i send "este/es/el/chat/java/" and obtaned in the server as "este:es:el:chat:java:"

    client:

    stompSession.send("/app/chat/este/es/el/chat/java/*", ...);
    

    server:

    @MessageMapping("/chat/**")
    @SendToUser("/queue/reply")
    public WebsocketData greeting(Message m,HelloMessage message,@Header("simpSessionId") String sessionId) throws Exception {
        Map> nativeHeaders = (Map>) m.getHeaders().get("nativeHeaders");
        String value= nativeHeaders.get("destination").getFirst().replaceAll("/app/chat/","").replaceAll("/",":");
    

提交回复
热议问题