Class PartitionedChannel

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ExecutorChannelInterceptorAware, ComponentSourceAware, ExpressionCapable, IntegrationPattern, NamedComponent, IntegrationManagement, SubscribableChannelManagement, TrackableComponent, MessageChannel, SubscribableChannel, InterceptableChannel

public class PartitionedChannel extends AbstractExecutorChannel
An AbstractExecutorChannel implementation for partitioned message dispatching. Requires a number of partitions where each of them is backed by a dedicated thread. The partitionKeyFunction is used to determine to which partition the message has to be dispatched. By default, the IntegrationMessageHeaderAccessor.CORRELATION_ID message header is used for a partition key.

The actual dispatching and threading logic is implemented in the PartitionedDispatcher.

The default ThreadFactory is based on the bean name of this channel plus -partition-thread-. Thus, every thread name will reflect a partition it belongs to.

The rest of the logic is similar to the ExecutorChannel, which includes: - load balancing for subscribers; - fail-over and error handling; - channel operations intercepting.

Since:
6.1
Author:
Artem Bilan
See Also:
  • Constructor Details

    • PartitionedChannel

      public PartitionedChannel(int partitionCount)
      Instantiate based on a provided number of partitions and function resolving a partition key from the IntegrationMessageHeaderAccessor.CORRELATION_ID message header.
      Parameters:
      partitionCount - the number of partitions in this channel. sent to this channel.
    • PartitionedChannel

      public PartitionedChannel(int partitionCount, Function<Message<?>, Object> partitionKeyFunction)
      Instantiate based on a provided number of partitions and function for a partition key against the message.
      Parameters:
      partitionCount - the number of partitions in this channel.
      partitionKeyFunction - the function to resolve a partition key against the message sent to this channel.
  • Method Details

    • setThreadFactory

      public void setThreadFactory(ThreadFactory threadFactory)
      Set a ThreadFactory for executors per partitions. Propagated down to the PartitionedDispatcher. Defaults to the CustomizableThreadFactory based on the bean name of this channel plus -partition-thread-.
      Parameters:
      threadFactory - the ThreadFactory to use.
    • setFailover

      public void setFailover(boolean failover)
      Specify whether the channel's dispatcher should have failover enabled. By default, it will. Set this value to 'false' to disable it.
      Parameters:
      failover - The failover boolean.
    • setFailoverStrategy

      public void setFailoverStrategy(Predicate<Exception> failoverStrategy)
      Configure a strategy whether the channel's dispatcher should have failover enabled for the exception thrown. Overrides setFailover(boolean) option. In other words: or this, or that option has to be set.
      Parameters:
      failoverStrategy - The failover boolean.
      Since:
      6.3
    • setLoadBalancingStrategy

      public void setLoadBalancingStrategy(@Nullable LoadBalancingStrategy loadBalancingStrategy)
      Parameters:
      loadBalancingStrategy - The load balancing strategy implementation.
    • setWorkerQueueSize

      public void setWorkerQueueSize(int workerQueueSize)
      Provide a size of the queue in the partition executor's worker. Default to zero.
      Parameters:
      workerQueueSize - the size of the partition executor's worker queue.
      Since:
      6.4.10
    • getDispatcher

      protected PartitionedDispatcher getDispatcher()
      Specified by:
      getDispatcher in class AbstractSubscribableChannel
    • onInit

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

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