我已经使用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");
}
有什么想法吗?
谢谢