Class PartitionedDispatcher

java.lang.Object
org.springframework.integration.dispatcher.AbstractDispatcher
org.springframework.integration.dispatcher.PartitionedDispatcher
All Implemented Interfaces:
MessageDispatcher

public class PartitionedDispatcher extends AbstractDispatcher
An AbstractDispatcher implementation for distributing messages to dedicated threads according to the key determined by the provided function against the message to dispatch.

Every partition, created by this class, is a UnicastingDispatcher delegate based on a single thread Executor.

The number of partitions should be a reasonable value for the application environment since every partition is based on a dedicated thread for message processing.

The rest of the logic is similar to UnicastingDispatcher behavior.

Since:
6.1
Author:
Artem Bilan, Christian Tzolov
  • Constructor Details

    • PartitionedDispatcher

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

    • setThreadFactory

      public void setThreadFactory(ThreadFactory threadFactory)
      Set a ThreadFactory for executors per partitions. Defaults to the CustomizableThreadFactory based on a partition-thread- prefix.
      Parameters:
      threadFactory - the ThreadFactory to use.
    • setFailover

      public void setFailover(boolean failover)
      Specify whether partition dispatchers 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)
      Provide a LoadBalancingStrategy for partition dispatchers.
      Parameters:
      loadBalancingStrategy - The load balancing strategy implementation.
    • setErrorHandler

      public void setErrorHandler(ErrorHandler errorHandler)
      Provide a ErrorHandler for wrapping partition Executor to the ErrorHandlingTaskExecutor.
      Parameters:
      errorHandler - the ErrorHandler to use.
    • setMessageHandlingTaskDecorator

      public void setMessageHandlingTaskDecorator(MessageHandlingTaskDecorator messageHandlingTaskDecorator)
      Set a MessageHandlingTaskDecorator to wrap a message handling task into some addition logic, e.g. message channel may provide an interception for its operations.
      Parameters:
      messageHandlingTaskDecorator - the MessageHandlingTaskDecorator to use.
    • shutdown

      public void shutdown()
      Shutdown this dispatcher on application close. The partition executors are shutdown and internal state of this instance is cleared.
    • dispatch

      public boolean dispatch(Message<?> message)
      Description copied from interface: MessageDispatcher
      Dispatch the message.
      Parameters:
      message - the message.
      Returns:
      true if dispatched.