Class MessagingGatewaySupport

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Lifecycle, Phased, SmartLifecycle, ExpressionCapable, IntegrationPattern, NamedComponent, IntegrationInboundManagement, IntegrationManagement, ManageableLifecycle, ManageableSmartLifecycle, TrackableComponent
Direct Known Subclasses:
AbstractWebServiceInboundGateway, AmqpInboundGateway, BaseHttpInboundEndpoint, JmsInboundGateway, KafkaInboundGateway, RedisQueueInboundGateway, RSocketInboundGateway, TcpInboundGateway

A convenient base class for connecting application code to MessageChannels for sending, receiving, or request-reply operations. Exposes setters for configuring request and reply MessageChannels as well as the timeout values for sending and receiving Messages.
Author:
Mark Fisher, Gary Russell, Artem Bilan, Trung Pham, Christian Tzolov
  • Field Details

  • Constructor Details

    • MessagingGatewaySupport

      public MessagingGatewaySupport()
      Construct an instance that will return null if no reply is received.
    • MessagingGatewaySupport

      public MessagingGatewaySupport(boolean errorOnTimeout)
      If errorOnTimeout is true, construct an instance that will send an ErrorMessage with a MessageTimeoutException payload to the error channel if a reply is expected but none is received. If no error channel is configured, the MessageTimeoutException will be thrown.
      Parameters:
      errorOnTimeout - true to create the error message.
      Since:
      4.2
      See Also:
  • Method Details

    • setErrorOnTimeout

      public void setErrorOnTimeout(boolean errorOnTimeout)
      If errorOnTimeout is true, construct an instance that will send an ErrorMessage with a MessageTimeoutException payload to the error channel if a reply is expected but none is received. If no error channel is configured, the MessageTimeoutException will be thrown.
      Parameters:
      errorOnTimeout - true to create the error message on reply timeout.
      Since:
      5.2.2
    • setRequestChannel

      public void setRequestChannel(MessageChannel requestChannel)
      Set the request channel.
      Parameters:
      requestChannel - the channel to which request messages will be sent
    • setRequestChannelName

      public void setRequestChannelName(String requestChannelName)
      Set the request channel name.
      Parameters:
      requestChannelName - the channel bean name to which request messages will be sent
      Since:
      4.1
    • setReplyChannel

      public void setReplyChannel(MessageChannel replyChannel)
      Set the reply channel. If no reply channel is provided, this gateway will always use an anonymous, temporary channel for handling replies.
      Parameters:
      replyChannel - the channel from which reply messages will be received
    • setReplyChannelName

      public void setReplyChannelName(String replyChannelName)
      Set the reply channel name. If no reply channel is provided, this gateway will always use an anonymous, temporary channel for handling replies.
      Parameters:
      replyChannelName - the channel bean name from which reply messages will be received
      Since:
      4.1
    • setErrorChannel

      public void setErrorChannel(MessageChannel errorChannel)
      Set the error channel. If no error channel is provided, this gateway will propagate Exceptions to the caller. To completely suppress Exceptions, provide a reference to the "nullChannel" here.
      Parameters:
      errorChannel - The error channel.
    • setErrorChannelName

      public void setErrorChannelName(String errorChannelName)
      Set the error channel name. If no error channel is provided, this gateway will propagate Exceptions to the caller. To completely suppress Exceptions, provide a reference to the "nullChannel" here.
      Parameters:
      errorChannelName - The error channel bean name.
      Since:
      4.1
    • setRequestTimeout

      public void setRequestTimeout(long requestTimeout)
      Set the timeout value for sending request messages. If not explicitly configured, the default is one second.
      Parameters:
      requestTimeout - the timeout value in milliseconds
    • setReplyTimeout

      public void setReplyTimeout(long replyTimeout)
      Set the timeout value for receiving reply messages. If not explicitly configured, the default is one second.
      Parameters:
      replyTimeout - the timeout value in milliseconds
    • setRequestMapper

      public void setRequestMapper(@Nullable InboundMessageMapper<?> requestMapper)
      Provide an InboundMessageMapper for creating request Messages from any object passed in a send or sendAndReceive operation.
      Parameters:
      requestMapper - The request mapper.
    • setReplyMapper

      public void setReplyMapper(OutboundMessageMapper<?> replyMapper)
      Provide an OutboundMessageMapper for mapping to objects from any reply Messages received in receive or sendAndReceive operations.
      Parameters:
      replyMapper - The reply mapper.
    • setShouldTrack

      public void setShouldTrack(boolean shouldTrack)
      Specify whether this gateway should be tracked in the Message History of Messages that originate from its send or sendAndReceive operations.
      Specified by:
      setShouldTrack in interface TrackableComponent
    • 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 IntegrationObjectSupport
    • setLoggingEnabled

      public void setLoggingEnabled(boolean enabled)
      Description copied from interface: IntegrationManagement
      Enable logging or not.
      Specified by:
      setLoggingEnabled in interface IntegrationManagement
      Parameters:
      enabled - false to disable.
    • isLoggingEnabled

      public boolean isLoggingEnabled()
      Description copied from interface: IntegrationManagement
      Return whether logging is enabled.
      Specified by:
      isLoggingEnabled in interface IntegrationManagement
      Returns:
      true if enabled.
    • setErrorMessageStrategy

      public final void setErrorMessageStrategy(ErrorMessageStrategy errorMessageStrategy)
      Set an ErrorMessageStrategy to use to build an error message when a exception occurs. Default is the DefaultErrorMessageStrategy.
      Parameters:
      errorMessageStrategy - the ErrorMessageStrategy.
      Since:
      4.3.10
    • getErrorMessageStrategy

      protected ErrorMessageStrategy getErrorMessageStrategy()
      Get an ErrorMessageStrategy to use to build an error message when a exception occurs. Default is the DefaultErrorMessageStrategy.
      Returns:
      the errorMessageStrategy.
      Since:
      6.0
    • getOverrides

      Description copied from interface: IntegrationManagement
      Return the overrides.
      Specified by:
      getOverrides in interface IntegrationManagement
      Returns:
      the overrides.
    • setManagedType

      public void setManagedType(String managedType)
      Specified by:
      setManagedType in interface IntegrationManagement
    • getManagedType

      public String getManagedType()
      Specified by:
      getManagedType in interface IntegrationManagement
    • setManagedName

      public void setManagedName(String managedName)
      Specified by:
      setManagedName in interface IntegrationManagement
    • getManagedName

      public String getManagedName()
      Specified by:
      getManagedName in interface IntegrationManagement
    • getIntegrationPatternType

      public IntegrationPatternType getIntegrationPatternType()
      Description copied from interface: IntegrationPattern
      Return a pattern type this component implements.
      Specified by:
      getIntegrationPatternType in interface IntegrationPattern
      Returns:
      the IntegrationPatternType this component implements.
    • registerMetricsCaptor

      public void registerMetricsCaptor(MetricsCaptor metricsCaptorToRegister)
      Description copied from interface: IntegrationManagement
      Inject a MetricsCaptor. Ignored if ObservationRegistry is provided.
      Specified by:
      registerMetricsCaptor in interface IntegrationManagement
      Parameters:
      metricsCaptorToRegister - the captor.
      See Also:
    • registerObservationRegistry

      public void registerObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)
      Description copied from interface: IntegrationManagement
      Inject an ObservationRegistry. If provided, the MetricsCaptor is ignored. The meters capturing has to be configured as an ObservationHandler on the provided ObservationRegistry.
      Specified by:
      registerObservationRegistry in interface IntegrationManagement
      Parameters:
      observationRegistry - the ObservationRegistry to expose observations from the component.
      See Also:
    • isObserved

      public boolean isObserved()
      Description copied from interface: IntegrationManagement
      True if this implementation is going to deal with a registry other than the ObservationRegistry.NOOP instance.
      Specified by:
      isObserved in interface IntegrationManagement
      Returns:
      true if this implementation is going to deal with a registry other than the ObservationRegistry.NOOP instance.
    • setObservationConvention

      public void setObservationConvention(@Nullable MessageRequestReplyReceiverObservationConvention observationConvention)
    • setReceiverObservationConvention

      public void setReceiverObservationConvention(MessageReceiverObservationConvention receiverObservationConvention)
    • onInit

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class AbstractEndpoint
    • getRequestChannel

      @Nullable public MessageChannel getRequestChannel()
      Return this gateway's request channel.
      Returns:
      the channel.
      Since:
      4.2
    • getReplyChannel

      @Nullable public MessageChannel getReplyChannel()
      Return this gateway's reply channel if any.
      Returns:
      the reply channel instance
      Since:
      5.1
    • getErrorChannel

      @Nullable public MessageChannel getErrorChannel()
      Return the error channel (if provided) to which error messages will be routed.
      Returns:
      the channel or null.
      Since:
      4.3
    • send

      protected void send(Object object)
    • receive

      @Nullable protected Object receive()
    • receiveMessage

      @Nullable protected Message<?> receiveMessage()
    • receive

      @Nullable protected Object receive(long timeout)
    • receiveMessage

      @Nullable protected Message<?> receiveMessage(long timeout)
    • sendAndReceive

      @Nullable protected Object sendAndReceive(Object object)
    • sendAndReceiveMessage

      @Nullable protected Message<?> sendAndReceiveMessage(Object object)
    • sendAndReceiveMessageReactive

      protected reactor.core.publisher.Mono<Message<?>> sendAndReceiveMessageReactive(Object object)
    • sendTimer

      protected TimerFacade sendTimer()
    • buildSendTimer

      protected TimerFacade buildSendTimer(boolean success, String exception)
    • buildErrorMessage

      protected final ErrorMessage buildErrorMessage(@Nullable Message<?> requestMessage, Throwable throwable)
      Build an error message for the message and throwable using the configured ErrorMessageStrategy.
      Parameters:
      requestMessage - the requestMessage.
      throwable - the throwable.
      Returns:
      the error message.
      Since:
      4.3.10
    • getErrorMessageAttributes

      protected AttributeAccessor getErrorMessageAttributes(@Nullable Message<?> message)
      Populate an AttributeAccessor to be used when building an error message with the errorMessageStrategy.
      Parameters:
      message - the message.
      Returns:
      the attributes.
      Since:
      4.3.10
    • registerReplyMessageCorrelatorIfNecessary

      protected void registerReplyMessageCorrelatorIfNecessary()
    • doStart

      protected void doStart()
      Description copied from class: AbstractEndpoint
      Subclasses must implement this method with the start behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.
      Specified by:
      doStart in class AbstractEndpoint
    • doStop

      protected void doStop()
      Description copied from class: AbstractEndpoint
      Subclasses must implement this method with the stop behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.
      Specified by:
      doStop in class AbstractEndpoint
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean
      Specified by:
      destroy in interface IntegrationManagement
      Overrides:
      destroy in class AbstractEndpoint