GreetingController.java 580 B

12345678910111213141516171819
  1. package com.example.messagingstompwebsocket;
  2. import org.springframework.messaging.handler.annotation.MessageMapping;
  3. import org.springframework.messaging.handler.annotation.SendTo;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.web.util.HtmlUtils;
  6. @Controller
  7. public class GreetingController {
  8. @MessageMapping("/hello")
  9. @SendTo("/topic/greetings")
  10. public Greeting greeting(HelloMessage message) throws Exception {
  11. Thread.sleep(1000); // simulated delay
  12. return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
  13. }
  14. }