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
,ComponentSourceAware
,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.RequestHandler
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplate
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addNewConnection
(TcpConnection connection) When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.protected void
doInit()
Subclasses may implement this method to provide component type information.protected AbstractConnectionFactory
protected Object
handleRequestMessage
(Message<?> requestMessage) Subclasses must implement this method to handle the request Message.boolean
boolean
Called by a TCPConnection when a new message arrives.void
removeDeadConnection
(TcpConnection connection) When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.void
setCloseStreamAfterSend
(boolean closeStreamAfterSend) Set to true to close the connection ouput stream after sending without closing the connection.void
setConnectionFactory
(AbstractClientConnectionFactory connectionFactory) void
setIntegrationEvaluationContext
(EvaluationContext evaluationContext) void
setRemoteTimeout
(long remoteTimeout) void
setRemoteTimeoutExpression
(Expression remoteTimeoutExpression) void
setReplyChannel
(MessageChannel replyChannel) Specify the Spring Integration reply channel.void
setReplyChannelName
(String replyChannel) Specify the Spring Integration reply channel name.void
setRequestTimeout
(long requestTimeout) 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.void
setUnsolicitedMessageChannel
(MessageChannel unsolicitedMessageChannel) Set the channel for unsolicited incoming messages, or late replies.void
setUnsolicitedMessageChannelName
(String unsolicitedMessageChannelName) Set the channel name for unsolicited incoming messages, or late replies.void
start()
void
stop()
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getIntegrationPatternType, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
Methods 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, updateNotPropagatedHeaders
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods 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, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods 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 anErrorMessage
is received. Default 2 seconds.- Parameters:
secondChanceDelay
- the delay.- Since:
- 5.0.8
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classMessageHandlerSupport
-
doInit
protected void doInit()- Overrides:
doInit
in classAbstractReplyProducingMessageHandler
-
handleRequestMessage
Description copied from class:AbstractReplyProducingMessageHandler
Subclasses 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:
handleRequestMessage
in classAbstractReplyProducingMessageHandler
- Parameters:
requestMessage
- The request message.- Returns:
- The result of handling the message, or
null
.
-
onMessage
Description copied from interface:TcpListener
Called by a TCPConnection when a new message arrives.- Specified by:
onMessage
in interfaceTcpListener
- Parameters:
message
- The message.- Returns:
- true if the message was intercepted
-
addNewConnection
Description copied from interface:TcpSender
When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.- Specified by:
addNewConnection
in interfaceTcpSender
- Parameters:
connection
- The connection.
-
removeDeadConnection
Description copied from interface:TcpSender
When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.- Specified by:
removeDeadConnection
in interfaceTcpSender
- Parameters:
connection
- The connection.
-
start
public void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
-
getConnectionFactory
- Returns:
- the connectionFactory
-