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<org.springframework.messaging.Message<?>>,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.Lifecycle,org.springframework.core.Ordered,org.springframework.integration.context.ExpressionCapable,org.springframework.integration.context.Orderable,org.springframework.integration.core.MessageProducer,org.springframework.integration.handler.HeaderPropagationAware,org.springframework.integration.IntegrationPattern,TcpListener,TcpSender,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.IntegrationManagement,org.springframework.integration.support.management.ManageableLifecycle,org.springframework.integration.support.management.TrackableComponent,org.springframework.messaging.MessageHandler,reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>
public class TcpOutboundGateway extends org.springframework.integration.handler.AbstractReplyProducingMessageHandler implements TcpSender, TcpListener, org.springframework.integration.support.management.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
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplateFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
Constructors Constructor Description TcpOutboundGateway() -
Method Summary
Modifier and Type Method Description voidaddNewConnection(TcpConnection connection)When we are using sockets owned by aTcpListener, this method is called each time a new connection is made.protected voiddoInit()java.lang.StringgetComponentType()protected AbstractConnectionFactorygetConnectionFactory()protected java.lang.ObjecthandleRequestMessage(org.springframework.messaging.Message<?> requestMessage)booleanisRunning()booleanonMessage(org.springframework.messaging.Message<?> message)Called 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(org.springframework.expression.EvaluationContext evaluationContext)voidsetRemoteTimeout(long remoteTimeout)voidsetRemoteTimeoutExpression(org.springframework.expression.Expression remoteTimeoutExpression)voidsetReplyChannel(org.springframework.messaging.MessageChannel replyChannel)Specify the Spring Integration reply channel.voidsetReplyChannelName(java.lang.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(org.springframework.messaging.MessageChannel unsolicitedMessageChannel)Set the channel for unsolicited incoming messages, or late replies.voidsetUnsolicitedMessageChannelName(java.lang.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, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadersMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribeMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, 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, wait
-
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
public void setRemoteTimeoutExpression(org.springframework.expression.Expression remoteTimeoutExpression)- Parameters:
remoteTimeoutExpression- the remoteTimeoutExpression to set
-
setIntegrationEvaluationContext
public void setIntegrationEvaluationContext(org.springframework.expression.EvaluationContext evaluationContext) -
setReplyChannel
public void setReplyChannel(org.springframework.messaging.MessageChannel replyChannel)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
public void setReplyChannelName(java.lang.String replyChannel)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
public void setUnsolicitedMessageChannelName(java.lang.String unsolicitedMessageChannelName)Set the channel name for unsolicited incoming messages, or late replies.- Parameters:
unsolicitedMessageChannelName- the channel name.- Since:
- 5.4
-
setUnsolicitedMessageChannel
public void setUnsolicitedMessageChannel(org.springframework.messaging.MessageChannel unsolicitedMessageChannel)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
public java.lang.String getComponentType()- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.handler.MessageHandlerSupport
-
doInit
protected void doInit()- Overrides:
doInitin classorg.springframework.integration.handler.AbstractReplyProducingMessageHandler
-
handleRequestMessage
protected java.lang.Object handleRequestMessage(org.springframework.messaging.Message<?> requestMessage)- Specified by:
handleRequestMessagein classorg.springframework.integration.handler.AbstractReplyProducingMessageHandler
-
onMessage
public boolean onMessage(org.springframework.messaging.Message<?> message)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 interfaceorg.springframework.context.Lifecycle- Specified by:
startin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle- Specified by:
stopin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle- Specified by:
isRunningin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
getConnectionFactory
- Returns:
- the connectionFactory
-