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

    Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler

    org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.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

    Constructors 
    Constructor Description
    TcpOutboundGateway()  
  • Method Summary

    Modifier and Type Method Description
    void addNewConnection​(TcpConnection connection)
    When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.
    protected void doInit()  
    java.lang.String getComponentType()  
    protected AbstractConnectionFactory getConnectionFactory()  
    protected java.lang.Object handleRequestMessage​(org.springframework.messaging.Message<?> requestMessage)  
    boolean isRunning()  
    boolean onMessage​(org.springframework.messaging.Message<?> message)
    Called by a TCPConnection when a new message arrives.
    void removeDeadConnection​(TcpConnection connection)
    When we are using sockets owned by a TcpListener, 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​(org.springframework.expression.EvaluationContext evaluationContext)  
    void setRemoteTimeout​(long remoteTimeout)  
    void setRemoteTimeoutExpression​(org.springframework.expression.Expression remoteTimeoutExpression)  
    void setReplyChannel​(org.springframework.messaging.MessageChannel replyChannel)
    Specify the Spring Integration reply channel.
    void setReplyChannelName​(java.lang.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​(org.springframework.messaging.MessageChannel unsolicitedMessageChannel)
    Set the channel for unsolicited incoming messages, or late replies.
    void setUnsolicitedMessageChannelName​(java.lang.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, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, 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, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, 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

  • Method Details

    • setConnectionFactory

      public void setConnectionFactory​(AbstractClientConnectionFactory connectionFactory)
    • 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 a ByteArrayRawSerializer. 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 an ErrorMessage is received. Default 2 seconds.
      Parameters:
      secondChanceDelay - the delay.
      Since:
      5.0.8
    • getComponentType

      public java.lang.String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.handler.MessageHandlerSupport
    • doInit

      protected void doInit()
      Overrides:
      doInit in class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
    • handleRequestMessage

      protected java.lang.Object handleRequestMessage​(org.springframework.messaging.Message<?> requestMessage)
      Specified by:
      handleRequestMessage in class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
    • onMessage

      public boolean onMessage​(org.springframework.messaging.Message<?> message)
      Description copied from interface: TcpListener
      Called by a TCPConnection when a new message arrives.
      Specified by:
      onMessage in interface TcpListener
      Parameters:
      message - The message.
      Returns:
      true if the message was intercepted
    • addNewConnection

      public void addNewConnection​(TcpConnection connection)
      Description copied from interface: TcpSender
      When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.
      Specified by:
      addNewConnection in interface TcpSender
      Parameters:
      connection - The connection.
    • removeDeadConnection

      public void removeDeadConnection​(TcpConnection connection)
      Description copied from interface: TcpSender
      When we are using sockets owned by a TcpListener, this method is called each time a connection is closed.
      Specified by:
      removeDeadConnection in interface TcpSender
      Parameters:
      connection - The connection.
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Specified by:
      start in interface org.springframework.integration.support.management.ManageableLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface org.springframework.integration.support.management.ManageableLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Specified by:
      isRunning in interface org.springframework.integration.support.management.ManageableLifecycle
    • getConnectionFactory

      protected AbstractConnectionFactory getConnectionFactory()
      Returns:
      the connectionFactory