Class TcpOutboundGateway
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.ip.tcp.TcpOutboundGateway
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>,Aware,BeanClassLoaderAware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,ApplicationContextAware,Lifecycle,Ordered,ExpressionCapable,Orderable,MessageProducer,HeaderPropagationAware,IntegrationPattern,TcpListener,TcpSender,NamedComponent,IntegrationManagement,ManageableLifecycle,TrackableComponent,MessageHandler,reactor.core.CoreSubscriber<Message<?>>
public class TcpOutboundGateway
extends AbstractReplyProducingMessageHandler
implements TcpSender, TcpListener, ManageableLifecycle
TCP outbound gateway that uses a client connection factory. If the factory is configured
for single-use connections, each request is sent on a new connection; if the factory does not use
single use connections, each request is blocked until the previous response is received
(or times out). Asynchronous requests/responses over the same connection are not
supported - use a pair of outbound/inbound adapters for that use case.
Lifecycle methods delegate to the underlying AbstractConnectionFactory.
- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandlerNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplateFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNewConnection(TcpConnection connection) When we are using sockets owned by aTcpListener, this method is called each time a new connection is made.protected voiddoInit()Subclasses may implement this method to provide component type information.protected AbstractConnectionFactoryprotected ObjecthandleRequestMessage(Message<?> requestMessage) Subclasses must implement this method to handle the request Message.booleanbooleanCalled by a TCPConnection when a new message arrives.voidremoveDeadConnection(TcpConnection connection) When we are using sockets owned by aTcpListener, this method is called each time a connection is closed.voidsetCloseStreamAfterSend(boolean closeStreamAfterSend) Set to true to close the connection ouput stream after sending without closing the connection.voidsetConnectionFactory(AbstractClientConnectionFactory connectionFactory) voidsetIntegrationEvaluationContext(EvaluationContext evaluationContext) voidsetRemoteTimeout(long remoteTimeout) voidsetRemoteTimeoutExpression(Expression remoteTimeoutExpression) voidsetReplyChannel(MessageChannel replyChannel) Specify the Spring Integration reply channel.voidsetReplyChannelName(String replyChannel) Specify the Spring Integration reply channel name.voidsetRequestTimeout(long requestTimeout) voidsetSecondChanceDelay(int secondChanceDelay) When using NIO and the server closes the socket after sending the reply, an error message representing the close may appear before the reply.voidsetUnsolicitedMessageChannel(MessageChannel unsolicitedMessageChannel) Set the channel for unsolicited incoming messages, or late replies.voidsetUnsolicitedMessageChannelName(String unsolicitedMessageChannelName) Set the channel name for unsolicited incoming messages, or late replies.voidstart()voidstop()Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getIntegrationPatternType, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReplyMethods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadersMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
TcpOutboundGateway
public TcpOutboundGateway()
-
-
Method Details
-
setConnectionFactory
-
setRequestTimeout
public void setRequestTimeout(long requestTimeout) - Parameters:
requestTimeout- the requestTimeout to set
-
setRemoteTimeout
public void setRemoteTimeout(long remoteTimeout) - Parameters:
remoteTimeout- the remoteTimeout to set
-
setRemoteTimeoutExpression
- Parameters:
remoteTimeoutExpression- the remoteTimeoutExpression to set
-
setIntegrationEvaluationContext
-
setReplyChannel
Specify the Spring Integration reply channel. If this property is not set the gateway will check for a 'replyChannel' header on the request.- Parameters:
replyChannel- The reply channel.
-
setReplyChannelName
Specify the Spring Integration reply channel name. If this property is not set the gateway will check for a 'replyChannel' header on the request.- Parameters:
replyChannel- The reply channel.- Since:
- 5.0
-
setUnsolicitedMessageChannelName
Set the channel name for unsolicited incoming messages, or late replies.- Parameters:
unsolicitedMessageChannelName- the channel name.- Since:
- 5.4
-
setUnsolicitedMessageChannel
Set the channel for unsolicited incoming messages, or late replies.- Parameters:
unsolicitedMessageChannel- the channel.- Since:
- 5.4
-
setCloseStreamAfterSend
public void setCloseStreamAfterSend(boolean closeStreamAfterSend) Set to true to close the connection ouput stream after sending without closing the connection. Use to signal EOF to the server, such as when using aByteArrayRawSerializer. Requires a single-use connection factory.- Parameters:
closeStreamAfterSend- true to close.- Since:
- 5.2
-
setSecondChanceDelay
public void setSecondChanceDelay(int secondChanceDelay) When using NIO and the server closes the socket after sending the reply, an error message representing the close may appear before the reply. Set the delay, in seconds, to wait for an actual reply after anErrorMessageis received. Default 2 seconds.- Parameters:
secondChanceDelay- the delay.- Since:
- 5.0.8
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
doInit
protected void doInit()- Overrides:
doInitin classAbstractReplyProducingMessageHandler
-
handleRequestMessage
Description copied from class:AbstractReplyProducingMessageHandlerSubclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.- Specified by:
handleRequestMessagein classAbstractReplyProducingMessageHandler- Parameters:
requestMessage- The request message.- Returns:
- The result of handling the message, or
null.
-
onMessage
Description copied from interface:TcpListenerCalled by a TCPConnection when a new message arrives.- Specified by:
onMessagein interfaceTcpListener- Parameters:
message- The message.- Returns:
- true if the message was intercepted
-
addNewConnection
Description copied from interface:TcpSenderWhen we are using sockets owned by aTcpListener, this method is called each time a new connection is made.- Specified by:
addNewConnectionin interfaceTcpSender- Parameters:
connection- The connection.
-
removeDeadConnection
Description copied from interface:TcpSenderWhen we are using sockets owned by aTcpListener, this method is called each time a connection is closed.- Specified by:
removeDeadConnectionin interfaceTcpSender- Parameters:
connection- The connection.
-
start
public void start()- Specified by:
startin interfaceLifecycle- Specified by:
startin interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stopin interfaceLifecycle- Specified by:
stopin interfaceManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle
-
getConnectionFactory
- Returns:
- the connectionFactory
-