Sergio Pinto opened SPR-14331 and commented
I have found that sometime an application need a persistent connection with Websockets.
Since Spring 4.2 I see that integrated STOMP with WebSocket, I tried STOMP but I found that you can't reconnect. SockJS can do it, but is disabled when using STOMP with Spring and SockJS.
I think Spring must include a class to easy implement a websocket client that can reconnect.
Actually I implemented a Java client that initially was based in a JavaScript WebSocket implementation that can reconnect. I'm using a proxy pattern to add the onReconnect() and_ reconnect()_ methods to my client. It is using an log-back algorithm to retry a new connection.
This could be a big plus to the websocket API with Spring.
Maybe the reconnect ability could be added to the STOMP version that actually is used in Spring latter.
Is possible add this to the Spring framework as a new package/class that could be used as a out-of-the-box basic websocket cliet with reconnection
Affects: 4.3 RC2
Issue Links: - #17968 Excessive SockJS Reconnection Attempts
2 votes, 3 watchers
Comment From: YBrecher
I was doing some research on this issue, and I found that the common practice for getting a Websocket to reconnect is to create an onClose listener that automatically calls the connect method each time the connection closes. Is there a reason why this method would not be sufficient for Spring?
Comment From: rstoyanchev
Yes, a callback when the connection is closed is essential for reconnect.
From the original description it's unclear what the exact issue or proposal is. SockJsClient
doesn't have a reconnect feature built into it, but the WebSocketHandler
passed to it has onClose
. At the level of StompWebSocketClient
, there is a similar handleTransportError
callback on StompSessionHandler
.
I'm closing but would reconsider a more concrete proposal.