Top Description Fields Constructors Methods
org.springframework.messaging.simp.stomp

public abstract Class StompClientSupport

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.messaging.simp.stomp.ReactorNettyTcpStompClient
Imports
java.util.Arrays, java.util.concurrent.TimeUnit, org.springframework.lang.Nullable, org.springframework.messaging.converter.MessageConverter, .SimpleMessageConverter, org.springframework.scheduling.TaskScheduler, org.springframework.util.Assert

Base class for STOMP client implementations.

Subclasses can connect over WebSocket or TCP using any library. When creating a new connection, a subclass can create an instance of DefaultStompSession which implements org.springframework.messaging.tcp.TcpConnectionHandler whose lifecycle methods the subclass must then invoke.

In effect, TcpConnectionHandler and TcpConnection are the contracts that any subclass must adapt to while using StompEncoder and StompDecoder to encode and decode STOMP messages.

Author
Rossen Stoyanchev
Since
4.2

Field Summary

Modifier and TypeField and Description
private long[]
private MessageConverter
private long
private TaskScheduler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected ConnectionHandlingStompSession

Returns:

the created session
createSession
(StompHeaders
headers for the STOMP CONNECT frame
connectHeaders
,
StompSessionHandler
the handler for the STOMP session
handler
)

Factory method for create and configure a new session.

public long[]
getDefaultHeartbeat()

Return the configured default heart-beat value (never null).

public MessageConverter
getMessageConverter()

Return the configured MessageConverter.

public long
getReceiptTimeLimit()

Return the configured receipt time limit.

public TaskScheduler
getTaskScheduler()

The configured TaskScheduler.

public boolean
isDefaultHeartbeatEnabled()

Determine whether heartbeats are enabled.

protected StompHeaders

Returns:

the modified headers
processConnectHeaders
(StompHeaders
the headers to modify
connectHeaders
)

Further initialize the StompHeaders, for example setting the heart-beat header if necessary.

public void
setDefaultHeartbeat(long[]
the value for the CONNECT "heart-beat" header
heartbeat
)

Configure the default value for the "heart-beat" header of the STOMP CONNECT frame.

public void
setMessageConverter(MessageConverter
the message converter to use
messageConverter
)

Set the MessageConverter to use to convert the payload of incoming and outgoing messages to and from byte[] based on object type and the "content-type" header.

public void
setReceiptTimeLimit(long receiptTimeLimit)

Configure the number of milliseconds before a receipt is considered expired.

public void
setTaskScheduler(TaskScheduler taskScheduler)

Configure a scheduler to use for heartbeats and for receipt tracking.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultHeartbeatback to summary
private long[] defaultHeartbeat
messageConverterback to summary
private MessageConverter messageConverter
receiptTimeLimitback to summary
private long receiptTimeLimit
taskSchedulerback to summary
private TaskScheduler taskScheduler
Annotations
@Nullable

Constructor Detail

StompClientSupportback to summary
public StompClientSupport()

Method Detail

createSessionback to summary
protected ConnectionHandlingStompSession createSession(StompHeaders connectHeaders, StompSessionHandler handler)

Factory method for create and configure a new session.

Parameters
connectHeaders:StompHeaders

headers for the STOMP CONNECT frame

handler:StompSessionHandler

the handler for the STOMP session

Returns:ConnectionHandlingStompSession

the created session

getDefaultHeartbeatback to summary
public long[] getDefaultHeartbeat()

Return the configured default heart-beat value (never null).

getMessageConverterback to summary
public MessageConverter getMessageConverter()

Return the configured MessageConverter.

getReceiptTimeLimitback to summary
public long getReceiptTimeLimit()

Return the configured receipt time limit.

getTaskSchedulerback to summary
public TaskScheduler getTaskScheduler()

The configured TaskScheduler.

Annotations
@Nullable
isDefaultHeartbeatEnabledback to summary
public boolean isDefaultHeartbeatEnabled()

Determine whether heartbeats are enabled.

Returns false if defaultHeartbeat is set to "0,0", and true otherwise.

processConnectHeadersback to summary
protected StompHeaders processConnectHeaders(StompHeaders connectHeaders)

Further initialize the StompHeaders, for example setting the heart-beat header if necessary.

Parameters
connectHeaders:StompHeaders

the headers to modify

Returns:StompHeaders

the modified headers

setDefaultHeartbeatback to summary
public void setDefaultHeartbeat(long[] heartbeat)

Configure the default value for the "heart-beat" header of the STOMP CONNECT frame. The first number represents how often the client will write or send a heart-beat. The second is how often the server should write. A value of 0 means no heart-beats.

By default this is set to "10000,10000" but subclasses may override that default and for example set it to "0,0" if they require a TaskScheduler to be configured first.

Note

that a heartbeat is sent only in case of inactivity, i.e. when no other messages are sent. This can present a challenge when using an external broker since messages with a non-broker destination represent activity but aren't actually forwarded to the broker. In that case you can configure a `TaskScheduler` through the org.springframework.messaging.simp.config.StompBrokerRelayRegistration which ensures a heartbeat is forwarded to the broker also when only messages with a non-broker destination are sent.

Parameters
heartbeat:long[]

the value for the CONNECT "heart-beat" header

See Also
https://stomp.github.io/stomp-specification-1.2.html#Heart-beating
setMessageConverterback to summary
public void setMessageConverter(MessageConverter messageConverter)

Set the MessageConverter to use to convert the payload of incoming and outgoing messages to and from byte[] based on object type and the "content-type" header.

By default, SimpleMessageConverter is configured.

Parameters
messageConverter:MessageConverter

the message converter to use

setReceiptTimeLimitback to summary
public void setReceiptTimeLimit(long receiptTimeLimit)

Configure the number of milliseconds before a receipt is considered expired.

By default set to 15,000 (15 seconds).

setTaskSchedulerback to summary
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.