私はspring websocket stompクライアントを使用します。以下のコード断片である:Spring websocket stompクライアント接続をキャプチャする方法は失われますか?
List<Transport> transports = new ArrayList<Transport>(2);
transports.add(new WebSocketTransport(new StandardWebSocketClient()));
transports.add(new RestTemplateXhrTransport());
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.add("Cookie", client.getCookieString());
SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new StringMessageConverter());
ListenableFuture<StompSession> future =
stompClient.connect(configuration.getApp().getWebsocketServerBase() + "/websocket/sa", headers, new MyWebSocketHandler());
future.addCallback(new SuccessCallback<StompSession>() {
public void onSuccess(StompSession stompSession) {
System.out.println("on Success!");
}
}, new FailureCallback() {
public void onFailure(Throwable throwable) {
System.out.println("on Failure!");
}
});
それは動作しますが、WebSocketのサーバーが閉じているときに、クライアントがメッセージを受信しません。
リスナーサーバーのクローズイベントはどのようにするのですか?
ConnectionLostException:STOMPセッションの接続が切断されずに失われた場合に発生します。 私はそれを使用します。 リファレンス: http://docs.spring.io/autorepo/docs/spring/4.3.3.BUILD-SNAPSHOT/javadoc-api/org/springframework/messaging/simp/stomp/package-summary.html – Sergio