大家好,我試圖將消息發送到端點踩不發送消息,但any.I現在用彈簧啓動與STOMP以下我沒有得到是我班SimpMessagingTemplate春季啓動
@Controller
public class GreetingController {
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Greeting greeting(HelloMessage message) throws Exception {
System.out.println(message.getName());
Thread.sleep(13000); // simulated delay
return new Greeting("Hello, " + message.getName() + "!");
}
}
@Controller
public class Testcont {
@Autowired
private SimpMessagingTemplate messageSender;
@RequestMapping(value="/Users/get",method=RequestMethod.POST)
@ResponseBody
public String getUser(@RequestParam(value = "userId") String userId, @RequestParam(value = "password") String password, @RequestParam(value="port") String port, HttpServletRequest request) {
HelloMessage mess=new HelloMessage();
mess.setName(userId);
messageSender.convertAndSend("/app/hello",mess);
return "Success";
}
和我的WebSocket的配置
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/hello").withSockJS();
}
}
我沒有在控制檯中發現任何錯誤。上面的代碼在Web瀏覽器中運行良好。
你是怎麼實現這個扎希德的?米卡住在同一問題上,我不明白答案 –