13

Spring MVC を使用して Web Socket を実装しましたが、正常に動作しています。つまり、このコードを使用して、あるブラウザーから別のブラウザーに開いていて、それらのソケットに対して開いています。

@MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public HelloMessage greeting(HelloMessage message) throws Exception {
        Thread.sleep(3000); // simulated delay
        return message;
    }

誰が通常の API コントローラーから @SendTo("/topic/greetings") を呼び出すかを教えてください。これを使用してみましたが、うまくいきません

@RequestMapping(value = "/sendMessage")
    @SendTo("/topic/greetings")
    public HelloMessage sendMessage() throws Exception {
        return new HelloMessage((int) Math.random(), "This is Send From Server");
    }

これについて何か考えはありますか?

ありがとう

4

1 に答える 1