public class WebSocketStompClient extends StompClientSupport implements SmartLifecycle
WebSocketClient
including SockJsClient
.DEFAULT_PHASE
Constructor and Description |
---|
WebSocketStompClient(WebSocketClient webSocketClient)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
ListenableFuture<StompSession> |
connect(java.lang.String url,
StompSessionHandler handler,
java.lang.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. |
ListenableFuture<StompSession> |
connect(java.lang.String url,
WebSocketHttpHeaders handshakeHeaders,
StompHeaders connectHeaders,
StompSessionHandler handler,
java.lang.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. |
ListenableFuture<StompSession> |
connect(java.lang.String url,
WebSocketHttpHeaders handshakeHeaders,
StompSessionHandler handler,
java.lang.Object... uriVariables)
An overloaded version of
connect(String, StompSessionHandler, Object...) that also
accepts WebSocketHttpHeaders to use for the WebSocket handshake. |
ListenableFuture<StompSession> |
connect(java.net.URI url,
WebSocketHttpHeaders handshakeHeaders,
StompHeaders connectHeaders,
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()
Check whether this component is currently running.
|
protected StompHeaders |
processConnectHeaders(StompHeaders connectHeaders)
Further initialize the StompHeaders, for example setting the heart-beat
header if necessary.
|
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(TaskScheduler taskScheduler)
Configure a scheduler to use for heartbeats and for receipt tracking.
|
void |
start()
Start this component.
|
void |
stop()
Stop this component, typically in a synchronous fashion, such that the component is
fully stopped upon return of this method.
|
createSession, getDefaultHeartbeat, getMessageConverter, getReceiptTimeLimit, getTaskScheduler, isDefaultHeartbeatEnabled, setDefaultHeartbeat, setMessageConverter, setReceiptTimeLimit
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
stop
public WebSocketStompClient(WebSocketClient webSocketClient)
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.webSocketClient
- the WebSocket client to connect withpublic WebSocketClient getWebSocketClient()
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler)
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 defaultHeartbeat
property to "10000,10000" if it is currently set to "0,0".
setTaskScheduler
in class StompClientSupport
public void setInboundMessageSizeLimit(int inboundMessageSizeLimit)
By default this is set to 64 * 1024 (64K).
public int getInboundMessageSizeLimit()
public void setAutoStartup(boolean autoStartup)
Default is "true".
public boolean isAutoStartup()
isAutoStartup
in interface SmartLifecycle
Lifecycle.start()
,
SmartLifecycle.getPhase()
,
LifecycleProcessor.onRefresh()
,
ConfigurableApplicationContext.refresh()
public void setPhase(int phase)
By default this is Integer.MAX_VALUE meaning that the WebSocket client is started as late as possible and stopped as soon as possible.
public int getPhase()
getPhase
in interface Phased
getPhase
in interface SmartLifecycle
SmartLifecycle.isAutoStartup()
,
Lifecycle.start()
,
SmartLifecycle.stop(Runnable)
,
DefaultLifecycleProcessor.getPhase(Lifecycle)
public void start()
Lifecycle
Should not throw an exception if the component is already running.
In the case of a container, this will propagate the start signal to all components that apply.
start
in interface Lifecycle
SmartLifecycle.isAutoStartup()
public void stop()
Lifecycle
SmartLifecycle
and its stop(Runnable)
variant when asynchronous stop behavior is necessary.
Note that this stop notification is not guaranteed to come before destruction:
On regular shutdown, Lifecycle
beans 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.
stop
in interface Lifecycle
SmartLifecycle.stop(Runnable)
,
DisposableBean.destroy()
public boolean isRunning()
Lifecycle
In the case of a container, this will return true
only if all
components that apply are currently running.
public ListenableFuture<StompSession> connect(java.lang.String url, StompSessionHandler handler, java.lang.Object... uriVars)
StompSessionHandler
when connected on the STOMP level after the CONNECTED frame is received.url
- the url to connect tohandler
- the session handleruriVars
- the URI variables to expand into the URLpublic ListenableFuture<StompSession> connect(java.lang.String url, @Nullable WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, java.lang.Object... uriVariables)
connect(String, StompSessionHandler, Object...)
that also
accepts WebSocketHttpHeaders
to use for the WebSocket handshake.url
- the url to connect tohandshakeHeaders
- the headers for the WebSocket handshakehandler
- the session handleruriVariables
- the URI variables to expand into the URLpublic ListenableFuture<StompSession> connect(java.lang.String url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler handler, java.lang.Object... uriVariables)
connect(String, StompSessionHandler, Object...)
that also accepts
WebSocketHttpHeaders
to use for the WebSocket handshake and
StompHeaders
for the STOMP CONNECT frame.url
- the url to connect tohandshakeHeaders
- headers for the WebSocket handshakeconnectHeaders
- headers for the STOMP CONNECT framehandler
- the session handleruriVariables
- the URI variables to expand into the URLpublic ListenableFuture<StompSession> connect(java.net.URI url, @Nullable WebSocketHttpHeaders handshakeHeaders, @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler)
connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)
that accepts a fully prepared URI
.url
- the url to connect tohandshakeHeaders
- the headers for the WebSocket handshakeconnectHeaders
- headers for the STOMP CONNECT framesessionHandler
- the STOMP session handlerprotected StompHeaders processConnectHeaders(@Nullable StompHeaders connectHeaders)
StompClientSupport
processConnectHeaders
in class StompClientSupport
connectHeaders
- the headers to modify