Spring websockets на моем сервере нормально отправляет сообщения websocket (через SockJS + STOMP), и клиент получает их, но сообщения от клиента не принимаются сервером, и, несмотря на часы исследований, я не вижу никакой причиныЗачем.Код ниже:
Клиент:
// SockJS socket connection does not exist yet, set it up:
if(!this.sockjsclient) {
this.sockjsclient = new SockJS('http://localhost:8080/stomp/');
}
// If STOMP instance (to send messages over the socket) does not exist yet, set it up:
if(!this.stompClient) {
this.stompClient = Stomp.over(this.sockjsclient);
// this.stompClient.debug = null // Turn off STOMP's default debug messages
this.stompClient.connect({}, () => {
mySubscription = this.stompClient.subscribe(topic, (message) => this.updateHeartbeat(message, callbackfn));
// SEND WEBSOCKET MESSAGE TO SERVER:
this.stompClient.send("/app/getstatus", {}, 'hello');
}, () => {
console.log('Websocket connection error');
})
}
// STOMP instance already exists, so use that existing connection:
else {
mySubscription = this.stompClient.subscribe(topic, (message) => this.updateHeartbeat(message, callbackfn));
}
Сервер:
@CompileStatic
@Configuration
@EnableWebSocketMessageBroker
class MainWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
void configureMessageBroker(MessageBrokerRegistry messageBrokerRegistry) {
messageBrokerRegistry.enableSimpleBroker "/queue", "/topic"
messageBrokerRegistry.setApplicationDestinationPrefixes("/app");
}
@Override
void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/stomp").setAllowedOrigins("*").withSockJS()
}
}
// GetStatus() IS NOT BEING CALLED FOR SOME REASON:
@Controller
public class ReceivedMsgController {
SimpMessagingTemplate brokerMessagingTemplate
@MessageMapping("/getstatus")
public String GetStatus(String msg) {
println('GetStatus() ' + msg)
brokerMessagingTemplate.convertAndSend('/topic/sometopic', "Your message was: " + msg)
}
}
Спасибо