O SimpMessagingTemplate não envia mensagens para o websocket
Eu tenho o seguinte contoller
@Controller
public class GreetingController
{
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Person greeting(String message) throws Exception {
Person person=new Person();
person.setAge(10);
return person;
}
@Autowired
private SimpMessagingTemplate template;
@RequestMapping(path="/meeting",method=RequestMethod.POST)
public @ResponseBody void greet() {
this.template.convertAndSend("/topic/greetings", "message");
}
}
e minha configuração é
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig1 extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/hello").withSockJS();
}
}
Portanto, de acordo com o documento da primavera, template.convertAndSend ("/ topic / greetings", "message") deve chamar o broker e o soquete da web mapeado será chamado.
Código para front-end usando SockJS
var socket = new SockJS('/hello');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/greetings', function(greeting){
console.log(JSON.parse(greeting.body));
});
// to send via the web service-WORKING ( but websocket not called in springs)
$.post("http://localhost:8080/meeting");
// to send via websocket - WORKING
stompClient.send("/app/hello", {}, JSON.stringify({ 'message':'message'}));
Não há erros no console. Posso conectá-lo através do SockJs e enviar mensagem para "/ topic / greetings", mas quero chamar um webService que, por sua vez, chama o web Socket. Então, depois de pesquisar muito, estou preso porque não há erros e não consigo encontrar uma maneira diferente de fazer isso na primavera.