Class StompBrokerRelayMessageHandler
- All Implemented Interfaces:
- Aware,- ApplicationEventPublisherAware,- Lifecycle,- Phased,- SmartLifecycle,- MessageHandler
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:
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Andy Wilkinson
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceContract for access to session counters.
- 
Field SummaryFieldsFields inherited from class org.springframework.messaging.simp.broker.AbstractBrokerMessageHandlerloggerFields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructorsConstructorDescriptionStompBrokerRelayMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) Create a StompBrokerRelayMessageHandler instance with the given message channels and destination prefixes.
- 
Method SummaryModifier and TypeMethodDescriptionReturn the configured login to use for connections to the STOMP broker on behalf of connected clients.Return the configured passcode to use for connections to the STOMP broker on behalf of connected clients.intReturn the current count of TCP connection to the broker.Return the configured header initializer.Return the STOMP message broker host.intReturn the STOMP message broker port.getStats()Return a structured object with internal state and counters.Return a String describing internal state and counters.longReturn the interval, in milliseconds, at which the "system" connection expects to receive heartbeats from the STOMP broker.longReturn the interval, in milliseconds, at which the "system" connection will send heartbeats to the STOMP broker.Return the login used for the shared "system" connection to the STOMP broker.Return the passcode used for the shared "system" connection to the STOMP broker.Return the configured map with subscriptions on the "system" connection.@Nullable TcpOperations<byte[]> Get the configured TCP client (nevernullunless not configured invoked and this method is invoked before the handler is started and hence a default implementation initialized).Return the configured virtual host value.protected voidhandleMessageInternal(Message<?> message) voidsetClientLogin(String clientLogin) Set the login to use when creating connections to the STOMP broker on behalf of connected clients.voidsetClientPasscode(String clientPasscode) Set the client passcode to use to create connections to the STOMP broker on behalf of connected clients.voidsetHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializerto apply to the headers of all messages created through theStompBrokerRelayMessageHandlerthat are sent to the client outbound message channel.voidsetRelayHost(String relayHost) Set the STOMP message broker host.voidsetRelayPort(int relayPort) Set the STOMP message broker port.voidsetSystemHeartbeatReceiveInterval(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.voidsetSystemHeartbeatSendInterval(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.voidsetSystemLogin(String systemLogin) Set the login for the shared "system" connection used to send messages to the STOMP broker from within the application, i.e.voidsetSystemPasscode(String systemPasscode) Set the passcode for the shared "system" connection used to send messages to the STOMP broker from within the application, i.e.voidsetSystemSubscriptions(@Nullable Map<String, MessageHandler> subscriptions) Configure one more destinations to subscribe to on the shared "system" connection along with MessageHandler's to handle received messages.voidsetTaskScheduler(@Nullable TaskScheduler taskScheduler) Configure theTaskSchedulerto use to reset client-to-broker message count in the current heartbeat period.voidsetTcpClient(@Nullable TcpOperations<byte[]> tcpClient) Configure a TCP client for managing TCP connections to the STOMP broker.voidsetVirtualHost(@Nullable String virtualHost) Set the value of the "host" header to use in STOMP CONNECT frames.protected voidprotected voidtoString()Methods inherited from class org.springframework.messaging.simp.broker.AbstractBrokerMessageHandlercheckDestinationPrefix, getApplicationEventPublisher, getBrokerChannel, getClientInboundChannel, getClientOutboundChannel, getClientOutboundChannelForSession, getDestinationPrefixes, getPhase, handleMessage, isAutoStartup, isBrokerAvailable, isPreservePublishOrder, isRunning, publishBrokerAvailableEvent, publishBrokerUnavailableEvent, setApplicationEventPublisher, setAutoStartup, setPhase, setPreservePublishOrder, setUserDestinationPredicate, start, stop, stop
- 
Field Details- 
SYSTEM_SESSION_ID
 
- 
- 
Constructor Details- 
StompBrokerRelayMessageHandlerpublic StompBrokerRelayMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel, SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) Create a StompBrokerRelayMessageHandler instance with the given message channels and destination prefixes.- Parameters:
- inboundChannel- the channel for receiving messages from clients (for example, WebSocket clients)
- outboundChannel- the channel for sending messages to clients (for example, WebSocket clients)
- brokerChannel- the channel for the application to send messages to the broker
- destinationPrefixes- the broker supported destination prefixes; destinations that do not match the given prefix are ignored.
 
 
- 
- 
Method Details- 
setRelayHostSet the STOMP message broker host.
- 
getRelayHostReturn the STOMP message broker host.
- 
setRelayPortpublic void setRelayPort(int relayPort) Set the STOMP message broker port.
- 
getRelayPortpublic int getRelayPort()Return the STOMP message broker port.
- 
setClientLoginSet the login to use when creating connections to the STOMP broker on behalf of connected clients.By default this is set to "guest". - See Also:
 
- 
getClientLoginReturn the configured login to use for connections to the STOMP broker on behalf of connected clients.- See Also:
 
- 
setClientPasscodeSet the client passcode to use to create connections to the STOMP broker on behalf of connected clients.By default this is set to "guest". - See Also:
 
- 
getClientPasscodeReturn the configured passcode to use for connections to the STOMP broker on behalf of connected clients.- See Also:
 
- 
setSystemLoginSet 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 (for example, REST/HTTP request handling method).By default this is set to "guest". 
- 
getSystemLoginReturn the login used for the shared "system" connection to the STOMP broker.
- 
setSystemPasscodeSet 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 (for example, REST/HTTP request handling method).By default this is set to "guest". 
- 
getSystemPasscodeReturn the passcode used for the shared "system" connection to the STOMP broker.
- 
setSystemHeartbeatSendIntervalpublic 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. A value of zero will prevent heartbeats from being sent to the broker.The default value is 10000. See class-level documentation for more information on the "system" connection. 
- 
getSystemHeartbeatSendIntervalpublic long getSystemHeartbeatSendInterval()Return the interval, in milliseconds, at which the "system" connection will send heartbeats to the STOMP broker.
- 
setSystemHeartbeatReceiveIntervalpublic 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. A value of zero will configure the connection to expect not to receive heartbeats from the broker.The default value is 10000. See class-level documentation for more information on the "system" connection. 
- 
getSystemHeartbeatReceiveIntervalpublic long getSystemHeartbeatReceiveInterval()Return the interval, in milliseconds, at which the "system" connection expects to receive heartbeats from the STOMP broker.
- 
setSystemSubscriptionsConfigure one more destinations to subscribe to on the shared "system" connection along with MessageHandler's to handle received messages.This is for internal use in a multi-application server scenario where servers forward messages to each other (for example, unresolved user destinations). - Parameters:
- subscriptions- the destinations to subscribe to.
 
- 
getSystemSubscriptionsReturn the configured map with subscriptions on the "system" connection.
- 
setVirtualHostSet the value of the "host" header to use in STOMP CONNECT frames. When this property is configured, a "host" header will be added to every STOMP frame sent to the STOMP broker. This may be useful for example in a cloud environment where the actual host to which the TCP connection is established is different from the host providing the cloud-based STOMP service.By default this property is not set. 
- 
getVirtualHost
- 
setTcpClientConfigure a TCP client for managing TCP connections to the STOMP broker.By default ReactorNettyTcpClientis used.Note: when this property is used, any hostorportspecified are effectively ignored.
- 
getTcpClientGet the configured TCP client (nevernullunless not configured invoked and this method is invoked before the handler is started and hence a default implementation initialized).
- 
setHeaderInitializerConfigure aMessageHeaderInitializerto apply to the headers of all messages created through theStompBrokerRelayMessageHandlerthat are sent to the client outbound message channel.By default this property is not set. 
- 
getHeaderInitializerReturn the configured header initializer.
- 
getStatsInfoReturn a String describing internal state and counters. EffectivelytoString()ongetStats().
- 
getStatsReturn a structured object with internal state and counters.- Since:
- 5.2
 
- 
getConnectionCountpublic int getConnectionCount()Return the current count of TCP connection to the broker.
- 
setTaskSchedulerConfigure theTaskSchedulerto use to reset client-to-broker message count in the current heartbeat period. For more details, seeStompBrokerRelayRegistration.setTaskScheduler(TaskScheduler).- Parameters:
- taskScheduler- the scheduler to use
- Since:
- 5.3
 
- 
getTaskScheduler
- 
startInternalprotected void startInternal()- Overrides:
- startInternalin class- AbstractBrokerMessageHandler
 
- 
stopInternalprotected void stopInternal()- Overrides:
- stopInternalin class- AbstractBrokerMessageHandler
 
- 
handleMessageInternal- Specified by:
- handleMessageInternalin class- AbstractBrokerMessageHandler
 
- 
toString
 
-