Class 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
  • Constructor Details

    • TcpOutboundGateway

      public TcpOutboundGateway()
  • 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(Expression remoteTimeoutExpression)
      Parameters:
      remoteTimeoutExpression - the remoteTimeoutExpression to set
    • setIntegrationEvaluationContext

      public void setIntegrationEvaluationContext(EvaluationContext evaluationContext)
    • setReplyChannel

      public void setReplyChannel(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(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(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(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 String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • doInit

      protected void doInit()
      Overrides:
      doInit in class AbstractReplyProducingMessageHandler
    • handleRequestMessage

      protected Object handleRequestMessage(Message<?> requestMessage)
      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 class AbstractReplyProducingMessageHandler
      Parameters:
      requestMessage - The request message.
      Returns:
      The result of handling the message, or null.
    • onMessage

      public boolean onMessage(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 Lifecycle
      Specified by:
      start in interface ManageableLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface Lifecycle
      Specified by:
      stop in interface ManageableLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
      Specified by:
      isRunning in interface ManageableLifecycle
    • getConnectionFactory

      protected AbstractConnectionFactory getConnectionFactory()
      Returns:
      the connectionFactory