Path variables in Spring WebSockets @SendTo mapping

前端 未结 3 2005
暖寄归人
暖寄归人 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:35

    Actually I think this is what you might be looking for:

    @Autorwired
    lateinit var template: SimpMessageTemplate;
    
    @MessageMapping("/class/{id}")
    @Throws(Exception::class)
    fun onOffer(@DestinationVariable("id") id: String?, @Payload msg: Message) {
        println("RECEIVED " + id)
        template.convertAndSend("/topic/class/$id", Message("The response"))
    }
    

    Hope this helps someone! :)

提交回复
热议问题