Spring boot 弹簧靴&x2B;Sockjs客户端脱机连接问题
我正在尝试将Spring Boot Stomp服务器与多个sockjs客户端脱机连接,但收到了警告 在建立连接之前,Websocket已关闭 接 GET net::ERR_中止404(未找到) 我正在使用Spring Boot版本2.1.2,在后端使用Spring boot 弹簧靴&x2B;Sockjs客户端脱机连接问题,spring-boot,spring-websocket,stomp,sockjs,Spring Boot,Spring Websocket,Stomp,Sockjs,我正在尝试将Spring Boot Stomp服务器与多个sockjs客户端脱机连接,但收到了警告 在建立连接之前,Websocket已关闭 接 GET net::ERR_中止404(未找到) 我正在使用Spring Boot版本2.1.2,在后端使用Spring Boot starter websocket包,在前端使用Angular 6和sockjs客户端1.3.0版。前端和后端都在端口8080上运行 我在关闭internet时遇到一些错误。如果internet已关闭,iframe将尝试访问
Spring Boot starter websocket
包,在前端使用Angular 6和sockjs客户端
1.3.0版。前端和后端都在端口8080上运行
我在关闭internet时遇到一些错误。如果internet已关闭,iframe将尝试访问
我在后端配置stomp server,通过将.setClientLibraryUrl
添加到可脱机访问的绝对路径来设置客户端库
registry.addEndpoint("/socket").setAllowedOrigins("*").withSockJS).setClientLibraryUrl("http://192.168.1.45/dist/sockjs.min.js");
然后打200分,好吗
弹簧靴:
WebSocketConfiguration(扩展AbstractWebSocketMessageBrokerConfiguration)
WebSocketController
private final SimpMessagingTemplate template;
@Autowired
WebSocketController(SimpMessagingTemplate template){
this.template=template;
}
@MessageMapping("/send/message")
public void onReceivedMessage( String destination , String message){
this.template.convertAndSend(destination , message);
}
public void convertAndSend(String url, Object o){
this.template.convertAndSend(url, o);
}
角度6:
测试组件
ngAfterViewInit() {
let ws = new SockJS('http://192.168.1.45:8080/socket');
this.stompClient = Stomp.over(ws);
let that = this;
that.stompClient.subscribe("/test", (message) => {
if (message.body) {
console.log(message.body);
}
});
that.stompClient.subscribe("/test2", (message) => {
if (message.body) {
console.log(message.body);
}
});
}
我以为只需将sockjs客户端库添加到一个离线可访问的路径就可以了,但我得到了警告
在建立连接之前,Websocket已关闭
接
“GET net::ERR_中止404(未找到)”
该库可以很好地与internet连接,但我需要它来处理在线和离线两种情况。我也遇到了同样的问题,我通过删除SockJs修复了它。 所以现在我只使用Stomp WebSocket SpringBoot服务(WebsocketConfiguration)中的更改: 我删除了.withSockJS()和.setClientLibraryUrl(../sockjs.min.js) 连接到websocket的Javascript代码中的更改:
const stompClient = Stomp.client(`ws://localhost:8080/justStomp`);
stompClient.heartbeat.outgoing = 0;
stompClient.heartbeat.incoming = 0;
stompClient.connect({ name: 'test' }, frame => this.stompSuccessCallBack(frame, stompClient), err => this.stompFailureCallBack(err));
我没有使用Stomp.over(sockjs),而是使用Stomp.client方法直接连接到websocket url。
我在后台有一个rabbitMQ和stomp插件,这只适用于2个心跳设置。看这里
registry.addEndpoint("/justStomp").setAllowedOrigins("*");
const stompClient = Stomp.client(`ws://localhost:8080/justStomp`);
stompClient.heartbeat.outgoing = 0;
stompClient.heartbeat.incoming = 0;
stompClient.connect({ name: 'test' }, frame => this.stompSuccessCallBack(frame, stompClient), err => this.stompFailureCallBack(err));