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

public Class StompBrokerRelayMessageHandler

extends AbstractBrokerMessageHandler
Class Inheritance
Imports
java.security.Principal, java.time.Duration, java.util.Collection, .HashMap, .Map, java.util.concurrent.CompletableFuture, .ConcurrentHashMap, .TimeUnit, java.util.concurrent.atomic.AtomicInteger, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageChannel, .MessageDeliveryException, .MessageHandler, .MessageHeaders, .SubscribableChannel, org.springframework.messaging.simp.SimpLogging, .SimpMessageHeaderAccessor, .SimpMessageType, org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler, org.springframework.messaging.support.MessageBuilder, .MessageHeaderAccessor, .MessageHeaderInitializer, org.springframework.messaging.tcp.FixedIntervalReconnectStrategy, .TcpConnection, .TcpOperations, org.springframework.messaging.tcp.reactor.ReactorNetty2TcpClient, .ReactorNettyCodec, .ReactorNettyTcpClient, .TcpMessageCodec, org.springframework.scheduling.TaskScheduler, org.springframework.util.Assert, .ClassUtils

A org.springframework.messaging.MessageHandler that handles messages by forwarding them to a STOMP broker.

For each new CONNECT message, an independent TCP connection to the broker is opened and used exclusively for all messages from the client that originated the CONNECT message. Messages from the same client are identified through the session id message header. Reversely, when the STOMP broker sends messages back on the TCP connection, those messages are enriched with the session id of the client and sent back downstream through the MessageChannel provided to the constructor.

This class also automatically opens a default "system" TCP connection to the message broker that is used for sending messages that originate from the server application (as opposed to from a client). Such messages are not associated with any client and therefore do not have a session id header. The "system" connection is effectively shared and cannot be used to receive messages. Several properties are provided to configure the "system" connection including:

Authors
Rossen Stoyanchev, Andy Wilkinson
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class
public static interface
StompBrokerRelayMessageHandler.Stats

Contract for access to session counters.

private class

Field Summary

Modifier and TypeField and Description
private String
private String
private final Map<String, StompBrokerRelayMessageHandler.RelayConnectionHandler>
private static final byte[]
private static final CompletableFuture<Void>
private MessageHeaderInitializer
private static final StompHeaderAccessor
private static final Message<byte[]>
private static final long
HEARTBEAT_MULTIPLIER

STOMP recommended error of margin for receiving heartbeats.

private static final int
MAX_TIME_TO_CONNECTED_FRAME

Heartbeat starts once CONNECTED frame with heartbeat settings is received.

private static final boolean
private static final boolean
private String
private int
private final StompBrokerRelayMessageHandler.DefaultStats
public static final String
SYSTEM_SESSION_ID

The system session ID.

private long
private long
private String
private String
private final Map<String, MessageHandler>
private TaskScheduler
private TcpOperations<byte[]>
private String
Inherited from org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler:
logger

Constructor Summary

AccessConstructor and Description
public
StompBrokerRelayMessageHandler(SubscribableChannel
the channel for receiving messages from clients (e.g. WebSocket clients)
inboundChannel
,
MessageChannel
the channel for sending messages to clients (e.g. WebSocket clients)
outboundChannel
,
SubscribableChannel
the channel for the application to send messages to the broker
brokerChannel
,
Collection<String>
the broker supported destination prefixes; destinations that do not match the given prefix are ignored.
destinationPrefixes
)

Create a StompBrokerRelayMessageHandler instance with the given message channels and destination prefixes.

Method Summary

Modifier and TypeMethod and Description
public String
getClientLogin()

Return the configured login to use for connections to the STOMP broker on behalf of connected clients.

public String
getClientPasscode()

Return the configured passcode to use for connections to the STOMP broker on behalf of connected clients.

public int
getConnectionCount()

Return the current count of TCP connection to the broker.

public MessageHeaderInitializer
getHeaderInitializer()

Return the configured header initializer.

public String
getRelayHost()

Return the STOMP message broker host.

public int
getRelayPort()

Return the STOMP message broker port.

public StompBrokerRelayMessageHandler.Stats
getStats()

Return a structured object with internal state and counters.

public String
getStatsInfo()

Return a String describing internal state and counters.

public long
getSystemHeartbeatReceiveInterval()

Return the interval, in milliseconds, at which the "system" connection expects to receive heartbeats from the STOMP broker.

public long
getSystemHeartbeatSendInterval()

Return the interval, in milliseconds, at which the "system" connection will send heartbeats to the STOMP broker.

public String
getSystemLogin()

Return the login used for the shared "system" connection to the STOMP broker.

public String
getSystemPasscode()

Return the passcode used for the shared "system" connection to the STOMP broker.

public Map<String, MessageHandler>
getSystemSubscriptions()

Return the configured map with subscriptions on the "system" connection.

public TaskScheduler
public TcpOperations<byte[]>
getTcpClient()

Get the configured TCP client (never null unless not configured invoked and this method is invoked before the handler is started and hence a default implementation initialized).

private String
public String
getVirtualHost()

Return the configured virtual host value.

protected void
private TcpOperations<byte[]>
public void
setClientLogin(String clientLogin)

Set the login to use when creating connections to the STOMP broker on behalf of connected clients.

public void
setClientPasscode(String clientPasscode)

Set the client passcode to use to create connections to the STOMP broker on behalf of connected clients.

public void
setHeaderInitializer(MessageHeaderInitializer headerInitializer)

Configure a MessageHeaderInitializer to apply to the headers of all messages created through the StompBrokerRelayMessageHandler that are sent to the client outbound message channel.

public void
setRelayHost(String relayHost)

Set the STOMP message broker host.

public void
setRelayPort(int relayPort)

Set the STOMP message broker port.

public void
setSystemHeartbeatReceiveInterval(long heartbeatReceiveInterval)

Set the maximum interval, in milliseconds, at which the "system" connection expects, in the absence of any other data, to receive a heartbeat from the STOMP broker.

public void
setSystemHeartbeatSendInterval(long systemHeartbeatSendInterval)

Set the interval, in milliseconds, at which the "system" connection will, in the absence of any other data being sent, send a heartbeat to the STOMP broker.

public void
setSystemLogin(String systemLogin)

Set the login for the shared "system" connection used to send messages to the STOMP broker from within the application, i.e. messages not associated with a specific client session (e.g. REST/HTTP request handling method).

public void
setSystemPasscode(String systemPasscode)

Set the passcode for the shared "system" connection used to send messages to the STOMP broker from within the application, i.e. messages not associated with a specific client session (e.g. REST/HTTP request handling method).

public void
setSystemSubscriptions(Map<String, MessageHandler>
the destinations to subscribe to.
subscriptions
)

Configure one more destinations to subscribe to on the shared "system" connection along with MessageHandler's to handle received messages.

public void
setTaskScheduler(TaskScheduler
the scheduler to use
taskScheduler
)

Configure the TaskScheduler to use to reset client-to-broker message count in the current heartbeat period.

public void
setTcpClient(TcpOperations<byte[]> tcpClient)

Configure a TCP client for managing TCP connections to the STOMP broker.

public void
setVirtualHost(String virtualHost)

Set the value of the "host" header to use in STOMP CONNECT frames.

protected void
protected void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler:
checkDestinationPrefixgetApplicationEventPublishergetBrokerChannelgetClientInboundChannelgetClientOutboundChannelgetClientOutboundChannelForSessiongetDestinationPrefixesgetPhasehandleMessageisAutoStartupisBrokerAvailableisPreservePublishOrderisRunningpublishBrokerAvailableEventpublishBrokerUnavailableEventsetApplicationEventPublishersetAutoStartupsetPhasesetPreservePublishOrdersetUserDestinationPredicatestartstopstop