Class PartitionedDispatcher
java.lang.Object
org.springframework.integration.dispatcher.AbstractDispatcher
org.springframework.integration.dispatcher.PartitionedDispatcher
- All Implemented Interfaces:
MessageDispatcher
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
-
Field Summary
Fields inherited from class org.springframework.integration.dispatcher.AbstractDispatcher
logger -
Constructor Summary
ConstructorsConstructorDescriptionPartitionedDispatcher(int partitionCount, Function<Message<?>, Object> partitionKeyFunction) Instantiate based on a provided number of partitions and function for partition key against the message to dispatch. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDispatch the message.voidsetErrorHandler(ErrorHandler errorHandler) voidsetFailover(boolean failover) Specify whether partition dispatchers should have failover enabled.voidsetFailoverStrategy(Predicate<Exception> failoverStrategy) Configure a strategy whether the channel's dispatcher should have failover enabled for the exception thrown.voidsetLoadBalancingStrategy(LoadBalancingStrategy loadBalancingStrategy) Provide aLoadBalancingStrategyfor partition dispatchers.voidsetMessageHandlingTaskDecorator(MessageHandlingTaskDecorator messageHandlingTaskDecorator) Set aMessageHandlingTaskDecoratorto wrap a message handling task into some addition logic, e.g.voidsetThreadFactory(ThreadFactory threadFactory) Set aThreadFactoryfor executors per partitions.voidshutdown()Shutdown this dispatcher on application close.Methods inherited from class org.springframework.integration.dispatcher.AbstractDispatcher
addHandler, getHandlerCount, getHandlers, removeHandler, setMaxSubscribers, toString, tryOptimizedDispatch
-
Constructor Details
-
PartitionedDispatcher
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
Set aThreadFactoryfor executors per partitions. Defaults to theCustomizableThreadFactorybased on apartition-thread-prefix.- Parameters:
threadFactory- theThreadFactoryto 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
Configure a strategy whether the channel's dispatcher should have failover enabled for the exception thrown. OverridessetFailover(boolean)option. In other words: or this, or that option has to be set.- Parameters:
failoverStrategy- The failover boolean.- Since:
- 6.3
-
setLoadBalancingStrategy
Provide aLoadBalancingStrategyfor partition dispatchers.- Parameters:
loadBalancingStrategy- The load balancing strategy implementation.
-
setErrorHandler
- Parameters:
errorHandler- theErrorHandlerto use.
-
setMessageHandlingTaskDecorator
public void setMessageHandlingTaskDecorator(MessageHandlingTaskDecorator messageHandlingTaskDecorator) Set aMessageHandlingTaskDecoratorto wrap a message handling task into some addition logic, e.g. message channel may provide an interception for its operations.- Parameters:
messageHandlingTaskDecorator- theMessageHandlingTaskDecoratorto 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
Description copied from interface:MessageDispatcherDispatch the message.- Parameters:
message- the message.- Returns:
- true if dispatched.
-