类 WebSocketStompClient
- java.lang.Object
- org.springframework.messaging.simp.stomp.StompClientSupport
- org.springframework.web.socket.messaging.WebSocketStompClient
- 所有已实现的接口:
Lifecycle,Phased,SmartLifecycle
public class WebSocketStompClient extends StompClientSupport implements SmartLifecycle
A STOMP over WebSocket client that connects using an implementation ofWebSocketClientincludingSockJsClient.- 从以下版本开始:
- 4.2
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 WebSocketStompClient(WebSocketClient webSocketClient)Class constructor.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ListenableFuture<StompSession>connect(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.ListenableFuture<StompSession>connect(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables)An overloaded version ofconnect(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake andStompHeadersfor the STOMP CONNECT frame.ListenableFuture<StompSession>connect(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables)An overloaded version ofconnect(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake.ListenableFuture<StompSession>connect(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler)An overloaded version ofconnect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)that accepts a fully preparedURI.intgetInboundMessageSizeLimit()Get the configured inbound message buffer size in bytes.intgetPhase()Return the configured phase.WebSocketClientgetWebSocketClient()Return the configured WebSocketClient.booleanisAutoStartup()Return the value for the 'autoStartup' property.booleanisRunning()Check 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.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.voidstop(Runnable callback)Indicates that a Lifecycle component must stop if it is currently running.从类继承的方法 org.springframework.messaging.simp.stomp.StompClientSupport
createSession, getDefaultHeartbeat, getMessageConverter, getReceiptTimeLimit, getTaskScheduler, isDefaultHeartbeatEnabled, setDefaultHeartbeat, setMessageConverter, setReceiptTimeLimit
构造器详细资料
WebSocketStompClient
public WebSocketStompClient(WebSocketClient webSocketClient)
Class 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.- 参数:
webSocketClient- the WebSocket client to connect with
方法详细资料
getWebSocketClient
public WebSocketClient getWebSocketClient()
Return the configured WebSocketClient.
setTaskScheduler
public void setTaskScheduler(TaskScheduler taskScheduler)
Configure 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".
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.
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.
start
public void start()
从接口复制的说明:LifecycleStart this component.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在接口中Lifecycle- 另请参阅:
SmartLifecycle.isAutoStartup()
stop
public void stop()
从接口复制的说明: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.
- 指定者:
stop在接口中Lifecycle- 另请参阅:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
stop
public void stop(Runnable callback)
从接口复制的说明:SmartLifecycleIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The
LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.- 指定者:
stop在接口中SmartLifecycle- 另请参阅:
Lifecycle.stop(),Phased.getPhase()
isRunning
public boolean isRunning()
从接口复制的说明: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
public ListenableFuture<StompSession> connect(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.- 参数:
url- the url to connect tohandler- the session handleruriVars- the URI variables to expand into the URL- 返回:
- a ListenableFuture for access to the session when ready for use
connect
public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables)
An overloaded version ofconnect(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto 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 URL- 返回:
- a ListenableFuture for access to the session when ready for use
connect
public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables)
An overloaded version ofconnect(String, StompSessionHandler, Object...)that also acceptsWebSocketHttpHeadersto use for the WebSocket handshake andStompHeadersfor 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 URL- 返回:
- a ListenableFuture for access to the session when ready for use
connect
public ListenableFuture<StompSession> connect(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler)
An overloaded version ofconnect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)that accepts a fully preparedURI.- 参数:
url- the url to connect tohandshakeHeaders- the headers for the WebSocket handshakeconnectHeaders- headers for the STOMP CONNECT framesessionHandler- the STOMP session handler- 返回:
- a ListenableFuture for access to the session when ready for use
processConnectHeaders
protected StompHeaders processConnectHeaders(StompHeaders connectHeaders)
从类复制的说明:StompClientSupportFurther initialize the StompHeaders, for example setting the heart-beat header if necessary.- 覆盖:
processConnectHeaders在类中StompClientSupport- 参数:
connectHeaders- the headers to modify- 返回:
- the modified headers