public class WebSocketStompClient extends StompClientSupport implements SmartLifecycle
WebSocketClient
including SockJsClient
.Constructor and Description |
---|
WebSocketStompClient(WebSocketClient webSocketClient)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
ListenableFuture<StompSession> |
connect(String url,
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. |
ListenableFuture<StompSession> |
connect(String url,
WebSocketHttpHeaders handshakeHeaders,
StompHeaders connectHeaders,
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. |
ListenableFuture<StompSession> |
connect(String url,
WebSocketHttpHeaders handshakeHeaders,
StompSessionHandler handler,
Object... uriVariables)
An overloaded version of
connect(String, StompSessionHandler, Object...) that also
accepts WebSocketHttpHeaders to use for the WebSocket handshake. |
ListenableFuture<StompSession> |
connect(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.
|
void |
stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.
|
createSession, getDefaultHeartbeat, getMessageConverter, getReceiptTimeLimit, getTaskScheduler, isDefaultHeartbeatEnabled, setDefaultHeartbeat, setMessageConverter, setReceiptTimeLimit
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(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()
,
Phased.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()
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 void stop(Runnable callback)
SmartLifecycle
The provided callback is used by the LifecycleProcessor
to support
an ordered, and potentially concurrent, shutdown of all components having a
common shutdown order value. The callback must be executed after
the SmartLifecycle
component does indeed stop.
The LifecycleProcessor
will call only this variant of the
stop
method; i.e. Lifecycle.stop()
will not be called for
SmartLifecycle
implementations unless explicitly delegated to within
the implementation of this method.
stop
in interface SmartLifecycle
Lifecycle.stop()
,
Phased.getPhase()
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(String url, StompSessionHandler handler, 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(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, 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(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, 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(URI url, WebSocketHttpHeaders handshakeHeaders, 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(StompHeaders connectHeaders)
StompClientSupport
processConnectHeaders
in class StompClientSupport
connectHeaders
- the headers to modify