SimpMessagingTemplate no envía mensajes a websocket
Tengo el siguiente controlador
@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");
}
}
y mi configuración es
@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();
}
}
Entonces, de acuerdo con spring doc template.convertAndSend ("/ topic / greetings", "message") debe llamar al intermediario y se llamará al socket web asignado.
Código para el 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'}));
No hay errores en la consola. Puedo conectarlo a través de SockJs y enviar un mensaje a "/ topic / greetings" pero quiero llamar a un servicio web que a cambio llama al Web Socket. Entonces, después de buscar mucho, estoy atascado porque no hay errores y no puedo encontrar una forma diferente de hacerlo en primavera.