Class AbstractMessageChannel

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.AbstractMessageChannel
All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ComponentSourceAware, ExpressionCapable, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageChannel, InterceptableChannel
Direct Known Subclasses:
AbstractAmqpChannel, AbstractJmsChannel, AbstractKafkaChannel, AbstractPollableChannel, AbstractSubscribableChannel, FluxMessageChannel, SubscribableRedisChannel, ZeroMqChannel

Base class for MessageChannel implementations providing common properties such as the channel name. Also provides the common functionality for sending and receiving Messages including the invocation of any ChannelInterceptors.
Author:
Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, Christian Tzolov
  • Field Details

  • Constructor Details

    • AbstractMessageChannel

      public AbstractMessageChannel()
  • Method Details

    • 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
    • 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.
    • setShouldTrack

      public void setShouldTrack(boolean shouldTrack)
      Specified by:
      setShouldTrack in interface TrackableComponent
    • 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:
    • getMetricsCaptor

      @Nullable protected MetricsCaptor getMetricsCaptor()
    • isLoggingEnabled

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

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

      public void setDatatypes(Class<?>... datatypes)
      Specify the Message payload datatype(s) supported by this channel. If a payload type does not match directly, but the 'conversionService' is available, then type conversion will be attempted in the order of the elements provided in this array.

      If this property is not set explicitly, any Message payload type will be accepted.

      Parameters:
      datatypes - The supported data types.
      See Also:
    • setInterceptors

      public void setInterceptors(List<ChannelInterceptor> interceptors)
      Set the list of channel interceptors. This will clear any existing interceptors.
      Specified by:
      setInterceptors in interface InterceptableChannel
      Parameters:
      interceptors - The list of interceptors.
    • addInterceptor

      public void addInterceptor(ChannelInterceptor interceptor)
      Add a channel interceptor to the end of the list.
      Specified by:
      addInterceptor in interface InterceptableChannel
      Parameters:
      interceptor - The interceptor.
    • addInterceptor

      public void addInterceptor(int index, ChannelInterceptor interceptor)
      Add a channel interceptor to the specified index of the list.
      Specified by:
      addInterceptor in interface InterceptableChannel
      Parameters:
      index - The index to add interceptor.
      interceptor - The interceptor.
    • setMessageConverter

      public void setMessageConverter(MessageConverter messageConverter)
      Specify the MessageConverter to use when trying to convert to one of this channel's supported datatypes (in order) for a Message whose payload does not already match.

      Note: only the MessageConverter.fromMessage(Message, Class) method is used. If the returned object is not a Message, the inbound headers will be copied; if the returned object is a Message, it is expected that the converter will have fully populated the headers; no further action is performed by the channel. If null is returned, conversion to the next datatype (if any) will be attempted. Defaults to a DefaultDatatypeChannelMessageConverter.

      Parameters:
      messageConverter - The message converter.
    • setObservationConvention

      public void setObservationConvention(@Nullable MessageSenderObservationConvention observationConvention)
    • getInterceptors

      public List<ChannelInterceptor> getInterceptors()
      Return a read-only list of the configured interceptors.
      Specified by:
      getInterceptors in interface InterceptableChannel
    • removeInterceptor

      public boolean removeInterceptor(ChannelInterceptor interceptor)
      Specified by:
      removeInterceptor in interface InterceptableChannel
    • removeInterceptor

      @Nullable public ChannelInterceptor removeInterceptor(int index)
      Specified by:
      removeInterceptor in interface InterceptableChannel
    • getIChannelInterceptorList

      protected AbstractMessageChannel.ChannelInterceptorList getIChannelInterceptorList()
      Exposes the interceptor list instance for subclasses.
      Returns:
      The channel interceptor list.
    • getOverrides

      Description copied from interface: IntegrationManagement
      Return the overrides.
      Specified by:
      getOverrides in interface IntegrationManagement
      Returns:
      the overrides.
    • 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.
    • onInit

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

      public String getFullChannelName()
      Returns the fully qualified channel name including the application context id, if available.
      Returns:
      The name.
    • send

      public boolean send(Message<?> message)
      Send a message on this channel. If the channel is at capacity, this method will block until either space becomes available or the sending thread is interrupted.
      Specified by:
      send in interface MessageChannel
      Parameters:
      message - the Message to send
      Returns:
      true if the message is sent successfully or false if the sending thread is interrupted.
    • send

      public boolean send(Message<?> messageArg, long timeout)
      Send a message on this channel. If the channel is at capacity, this method will block until either the timeout occurs or the sending thread is interrupted. If the specified timeout is 0, the method will return immediately. If less than zero, it will block indefinitely (see send(Message)).
      Specified by:
      send in interface MessageChannel
      Parameters:
      messageArg - the Message to send
      timeout - the timeout in milliseconds
      Returns:
      true if the message is sent successfully, false if the message cannot be sent within the allotted time or the sending thread is interrupted.
    • doSend

      protected abstract boolean doSend(Message<?> message, long timeout)
      Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is at capacity (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either the message is accepted or the blocking thread is interrupted.
      Parameters:
      message - The message.
      timeout - The timeout.
      Returns:
      true if the send was successful.
    • destroy

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