Class WebSocketStompClient
- All Implemented Interfaces:
- Lifecycle,- Phased,- SmartLifecycle
WebSocketClient
 including SockJsClient.- Since:
- 4.2
- Author:
- Rossen Stoyanchev, Injae Kim
- 
Field SummaryFields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionconnect(String url, StompSessionHandler handler, Object... uriVars) Deprecated, for removal: This API element is subject to removal in a future version.connect(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(String, WebSocketHttpHeaders, StompHeaders, StompSessionHandler, Object...)connect(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)connect(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(URI, WebSocketHttpHeaders, StompHeaders, StompSessionHandler)connectAsync(String url, StompSessionHandler handler, Object... uriVars) Connect to the given WebSocket URL and notify the givenStompSessionHandlerwhen connected on the STOMP level after the CONNECTED frame is received.connectAsync(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) An overloaded version ofconnectAsync(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake andStompHeadersfor the STOMP CONNECT frame.connectAsync(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) An overloaded version ofconnectAsync(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake.connectAsync(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler) An overloaded version ofconnectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)that accepts a fully preparedURI.intGet the configured inbound message buffer size in bytes.Get the configured outbound message buffer size in bytes.intgetPhase()Return the configured phase.Return the configured WebSocketClient.booleanReturn the value for the 'autoStartup' property.booleanCheck whether this component is currently running.protected StompHeadersprocessConnectHeaders(StompHeaders connectHeaders) Further initialize the StompHeaders, for example setting the heart-beat header if necessary.voidsetAutoStartup(boolean autoStartup) Set whether to auto-start the contained WebSocketClient when the Spring context has been refreshed.voidsetInboundMessageSizeLimit(int inboundMessageSizeLimit) Configure the maximum size allowed for inbound STOMP message.voidsetOutboundMessageSizeLimit(Integer outboundMessageSizeLimit) Configure the maximum size allowed for outbound STOMP message.voidsetPhase(int phase) Specify the phase in which the WebSocket client should be started and subsequently closed.voidsetTaskScheduler(TaskScheduler taskScheduler) Configure a scheduler to use for heartbeats and for receipt tracking.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.Methods inherited from class org.springframework.messaging.simp.stomp.StompClientSupportcreateSession, getDefaultHeartbeat, getMessageConverter, getReceiptTimeLimit, getTaskScheduler, isDefaultHeartbeatEnabled, setDefaultHeartbeat, setMessageConverter, setReceiptTimeLimitMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecyclestop
- 
Constructor Details- 
WebSocketStompClientClass constructor. SetsStompClientSupport.setDefaultHeartbeat(long[])to "0,0" but will reset it back to the preferred "10000,10000" when asetTaskScheduler(org.springframework.scheduling.TaskScheduler)is configured.- Parameters:
- webSocketClient- the WebSocket client to connect with
 
 
- 
- 
Method Details- 
getWebSocketClientReturn the configured WebSocketClient.
- 
setTaskSchedulerConfigure a scheduler to use for heartbeats and for receipt tracking.Note: Some transports have built-in support to work with heartbeats and therefore do not require a TaskScheduler. Receipts however, if needed, do require a TaskScheduler to be configured. By default, this is not set. Also automatically sets the defaultHeartbeatproperty to "10000,10000" if it is currently set to "0,0".- Overrides:
- setTaskSchedulerin class- StompClientSupport
 
- 
setInboundMessageSizeLimitpublic void setInboundMessageSizeLimit(int inboundMessageSizeLimit) Configure the maximum size allowed for inbound STOMP message. Since a STOMP message can be received in multiple WebSocket messages, buffering may be required and this property determines the maximum buffer size per message.By default this is set to 64 * 1024 (64K). 
- 
getInboundMessageSizeLimitpublic int getInboundMessageSizeLimit()Get the configured inbound message buffer size in bytes.
- 
setOutboundMessageSizeLimitConfigure the maximum size allowed for outbound STOMP message. If STOMP message's size exceedsoutboundMessageSizeLimit, STOMP message is split into multiple frames.By default this is not set in which case each STOMP message are not split. - Since:
- 6.2
 
- 
getOutboundMessageSizeLimitGet the configured outbound message buffer size in bytes.- Since:
- 6.2
 
- 
setAutoStartuppublic void setAutoStartup(boolean autoStartup) Set whether to auto-start the contained WebSocketClient when the Spring context has been refreshed.Default is "true". 
- 
isAutoStartuppublic boolean isAutoStartup()Return the value for the 'autoStartup' property. If "true", this client will automatically start and stop the contained WebSocketClient.- Specified by:
- isAutoStartupin interface- SmartLifecycle
- See Also:
 
- 
setPhasepublic void setPhase(int phase) Specify the phase in which the WebSocket client should be started and subsequently closed. The startup order proceeds from lowest to highest, and the shutdown order is the reverse of that.By default this is Integer.MAX_VALUE meaning that the WebSocket client is started as late as possible and stopped as soon as possible. 
- 
getPhasepublic int getPhase()Return the configured phase.- Specified by:
- getPhasein interface- Phased
- Specified by:
- getPhasein interface- SmartLifecycle
- See Also:
 
- 
startpublic void start()Description copied from interface:LifecycleStart this component.Should not throw an exception if the component is already running. In the case of a container, this will propagate a hard start signal to all components that apply, even to non-auto-startup components. 
- 
stoppublic void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecyclebeans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet). In the case of a container, this will propagate the stop signal to all components that apply. 
- 
isRunningpublic boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return trueonly if all components that apply are currently running.
- 
connect@Deprecated(since="6.0", forRemoval=true) public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(String, StompSessionHandler, Object...)Connect to the given WebSocket URL and notify the givenStompSessionHandlerwhen connected on the STOMP level after the CONNECTED frame is received.- Parameters:
- url- the url to connect to
- handler- the session handler
- uriVars- the URI variables to expand into the URL
- Returns:
- a ListenableFuturefor access to the session when ready for use
 
- 
connectAsyncpublic CompletableFuture<StompSession> connectAsync(String url, StompSessionHandler handler, Object... uriVars) Connect to the given WebSocket URL and notify the givenStompSessionHandlerwhen connected on the STOMP level after the CONNECTED frame is received.- Parameters:
- url- the url to connect to
- handler- the session handler
- uriVars- the URI variables to expand into the URL
- Returns:
- a CompletableFuture for access to the session when ready for use
- Since:
- 6.0
 
- 
connect@Deprecated(since="6.0", forRemoval=true) public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)An overloaded version ofconnectAsync(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake.- Parameters:
- url- the url to connect to
- handshakeHeaders- the headers for the WebSocket handshake
- handler- the session handler
- uriVariables- the URI variables to expand into the URL
- Returns:
- a ListenableFuturefor access to the session when ready for use
 
- 
connectAsyncpublic CompletableFuture<StompSession> connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables) An overloaded version ofconnectAsync(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake.- Parameters:
- url- the url to connect to
- handshakeHeaders- the headers for the WebSocket handshake
- handler- the session handler
- uriVariables- the URI variables to expand into the URL
- Returns:
- a ListenableFuturefor access to the session when ready for use
- Since:
- 6.0
 
- 
connect@Deprecated(since="6.0", forRemoval=true) public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(String, WebSocketHttpHeaders, StompHeaders, StompSessionHandler, Object...)An overloaded version ofconnectAsync(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake andStompHeadersfor the STOMP CONNECT frame.- Parameters:
- url- the url to connect to
- handshakeHeaders- headers for the WebSocket handshake
- connectHeaders- headers for the STOMP CONNECT frame
- handler- the session handler
- uriVariables- the URI variables to expand into the URL
- Returns:
- a ListenableFuturefor access to the session when ready for use
 
- 
connectAsyncpublic CompletableFuture<StompSession> connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) An overloaded version ofconnectAsync(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake andStompHeadersfor the STOMP CONNECT frame.- Parameters:
- url- the url to connect to
- handshakeHeaders- headers for the WebSocket handshake
- connectHeaders- headers for the STOMP CONNECT frame
- handler- the session handler
- uriVariables- the URI variables to expand into the URL
- Returns:
- a CompletableFuture for access to the session when ready for use
- Since:
- 6.0
 
- 
connect@Deprecated(since="6.0", forRemoval=true) public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) Deprecated, for removal: This API element is subject to removal in a future version.as of 6.0, in favor ofconnectAsync(URI, WebSocketHttpHeaders, StompHeaders, StompSessionHandler)An overloaded version ofconnectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)that accepts a fully preparedURI.- Parameters:
- url- the url to connect to
- handshakeHeaders- the headers for the WebSocket handshake
- connectHeaders- headers for the STOMP CONNECT frame
- sessionHandler- the STOMP session handler
- Returns:
- a ListenableFuturefor access to the session when ready for use
 
- 
connectAsyncpublic CompletableFuture<StompSession> connectAsync(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) An overloaded version ofconnectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)that accepts a fully preparedURI.- Parameters:
- url- the url to connect to
- handshakeHeaders- the headers for the WebSocket handshake
- connectHeaders- headers for the STOMP CONNECT frame
- sessionHandler- the STOMP session handler
- Returns:
- a CompletableFuture for access to the session when ready for use
- Since:
- 6.0
 
- 
processConnectHeadersDescription copied from class:StompClientSupportFurther initialize the StompHeaders, for example setting the heart-beat header if necessary.- Overrides:
- processConnectHeadersin class- StompClientSupport
- Parameters:
- connectHeaders- the headers to modify
- Returns:
- the modified headers
 
 
- 
connectAsync(String, StompSessionHandler, Object...)