org.springframework.web.socket.messaging

## Class WebSocketStompClient

- java.lang.Object
- - org.springframework.messaging.simp.stomp.StompClientSupport
  - - org.springframework.web.socket.messaging.WebSocketStompClient

All Implemented Interfaces:
  org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

    public class WebSocketStompClient
    extends org.springframework.messaging.simp.stomp.StompClientSupport
    implements org.springframework.context.SmartLifecycle

A STOMP over WebSocket client that connects using an implementation of `WebSocketClient` including `SockJsClient`.

Since:
  4.2
Author:
  Rossen Stoyanchev

### Field Summary

### Fields inherited from interface org.springframework.context.SmartLifecycle

`DEFAULT_PHASE`

### Constructor Summary

Constructors
Constructor and Description
`WebSocketStompClient(WebSocketClient webSocketClient)` Class constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession>` `connect(String url, org.springframework.messaging.simp.stomp.StompSessionHandler handler, Object... uriVars)` Connect to the given WebSocket URL and notify the given `StompSessionHandler` when connected on the STOMP level after the CONNECTED frame is received.

`org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession>`

`connect(String url, WebSocketHttpHeaders handshakeHeaders, org.springframework.messaging.simp.stomp.StompHeaders connectHeaders, org.springframework.messaging.simp.stomp.StompSessionHandler handler, Object... uriVariables)`
An overloaded version of `connect(String, StompSessionHandler, Object...)` that also accepts `WebSocketHttpHeaders` to use for the WebSocket handshake and `StompHeaders` for the STOMP CONNECT frame.

`org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession>`

`connect(String url, WebSocketHttpHeaders handshakeHeaders, org.springframework.messaging.simp.stomp.StompSessionHandler handler, Object... uriVariables)`
An overloaded version of `connect(String, StompSessionHandler, Object...)` that also accepts `WebSocketHttpHeaders` to use for the WebSocket handshake.

`org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession>`

`connect(URI url, WebSocketHttpHeaders handshakeHeaders, org.springframework.messaging.simp.stomp.StompHeaders connectHeaders, org.springframework.messaging.simp.stomp.StompSessionHandler sessionHandler)`
An overloaded version of `connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)` that accepts a fully prepared `URI`.

`int` `getInboundMessageSizeLimit()` Get the configured inbound message buffer size in bytes.
`int` `getPhase()` Return the configured phase.
`WebSocketClient` `getWebSocketClient()` Return the configured WebSocketClient.
`boolean` `isAutoStartup()` Return the value for the 'autoStartup' property.
`boolean` `isRunning()`
`protected org.springframework.messaging.simp.stomp.StompHeaders` `processConnectHeaders(org.springframework.messaging.simp.stomp.StompHeaders connectHeaders)`
`void` `setAutoStartup(boolean autoStartup)` Set whether to auto-start the contained WebSocketClient when the Spring context has been refreshed.
`void` `setInboundMessageSizeLimit(int inboundMessageSizeLimit)` Configure the maximum size allowed for inbound STOMP message.
`void` `setPhase(int phase)` Specify the phase in which the WebSocket client should be started and subsequently closed.
`void` `setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)`
`void` `start()`
`void` `stop()`

### Methods inherited from class org.springframework.messaging.simp.stomp.StompClientSupport

`createSession, getDefaultHeartbeat, getMessageConverter, getReceiptTimeLimit, getTaskScheduler, isDefaultHeartbeatEnabled, setDefaultHeartbeat, setMessageConverter, setReceiptTimeLimit`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.context.SmartLifecycle

`stop`

### Constructor Detail

#### WebSocketStompClient

    public WebSocketStompClient(WebSocketClient webSocketClient)

Class constructor. Sets `StompClientSupport.setDefaultHeartbeat(long[])` to "0,0" but will reset it back to the preferred "10000,10000" when a `setTaskScheduler(org.springframework.scheduling.TaskScheduler)` is configured.

Parameters:
  `webSocketClient` - the WebSocket client to connect with

### Method Detail

#### getWebSocketClient

    public WebSocketClient getWebSocketClient()

Return the configured WebSocketClient.

#### setTaskScheduler

    public void setTaskScheduler(@Nullable
                                 org.springframework.scheduling.TaskScheduler taskScheduler)

Also automatically sets the `defaultHeartbeat` property to "10000,10000" if it is currently set to "0,0".

Overrides:
  `setTaskScheduler` in class `org.springframework.messaging.simp.stomp.StompClientSupport`

#### setInboundMessageSizeLimit

    public 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).

#### getInboundMessageSizeLimit

    public int getInboundMessageSizeLimit()

Get the configured inbound message buffer size in bytes.

#### setAutoStartup

    public void setAutoStartup(boolean autoStartup)

Set whether to auto-start the contained WebSocketClient when the Spring context has been refreshed.

Default is "true".

#### isAutoStartup

    public boolean isAutoStartup()

Return the value for the 'autoStartup' property. If "true", this client will automatically start and stop the contained WebSocketClient.

Specified by:
  `isAutoStartup` in interface `org.springframework.context.SmartLifecycle`

#### setPhase

    public 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.

#### getPhase

    public int getPhase()

Return the configured phase.

Specified by:
  `getPhase` in interface `org.springframework.context.Phased`
Specified by:
  `getPhase` in interface `org.springframework.context.SmartLifecycle`

#### start

    public void start()

Specified by:
  `start` in interface `org.springframework.context.Lifecycle`

#### stop

    public void stop()

Specified by:
  `stop` in interface `org.springframework.context.Lifecycle`

#### isRunning

    public boolean isRunning()

Specified by:
  `isRunning` in interface `org.springframework.context.Lifecycle`

#### connect

    public org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession> connect(String url,
                                                                                                                               org.springframework.messaging.simp.stomp.StompSessionHandler handler,
                                                                                                                               Object... uriVars)

Connect to the given WebSocket URL and notify the given `StompSessionHandler` when 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 ListenableFuture for access to the session when ready for use

#### connect

    public org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession> connect(String url,
                                                                                                                               @Nullable
                                                                                                                               WebSocketHttpHeaders handshakeHeaders,
                                                                                                                               org.springframework.messaging.simp.stomp.StompSessionHandler handler,
                                                                                                                               Object... uriVariables)

An overloaded version of `connect(String, StompSessionHandler, Object...)` that also accepts `WebSocketHttpHeaders` to 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 ListenableFuture for access to the session when ready for use

#### connect

    public org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession> connect(String url,
                                                                                                                               @Nullable
                                                                                                                               WebSocketHttpHeaders handshakeHeaders,
                                                                                                                               @Nullable
                                                                                                                               org.springframework.messaging.simp.stomp.StompHeaders connectHeaders,
                                                                                                                               org.springframework.messaging.simp.stomp.StompSessionHandler handler,
                                                                                                                               Object... uriVariables)

An overloaded version of `connect(String, StompSessionHandler, Object...)` that also accepts `WebSocketHttpHeaders` to use for the WebSocket handshake and `StompHeaders` for 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 ListenableFuture for access to the session when ready for use

#### connect

    public org.springframework.util.concurrent.ListenableFuture<org.springframework.messaging.simp.stomp.StompSession> connect(URI url,
                                                                                                                               @Nullable
                                                                                                                               WebSocketHttpHeaders handshakeHeaders,
                                                                                                                               @Nullable
                                                                                                                               org.springframework.messaging.simp.stomp.StompHeaders connectHeaders,
                                                                                                                               org.springframework.messaging.simp.stomp.StompSessionHandler sessionHandler)

An overloaded version of `connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)` that accepts a fully prepared `URI`.

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 ListenableFuture for access to the session when ready for use

#### processConnectHeaders

    protected org.springframework.messaging.simp.stomp.StompHeaders processConnectHeaders(@Nullable
                                                                                          org.springframework.messaging.simp.stomp.StompHeaders connectHeaders)

Overrides:
  `processConnectHeaders` in class `org.springframework.messaging.simp.stomp.StompClientSupport`