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
-
Field Summary
Fields inherited from class org.springframework.integration.dispatcher.AbstractDispatcher
logger
-
Constructor Summary
ConstructorDescriptionPartitionedDispatcher
(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 TypeMethodDescriptionboolean
Dispatch the message.void
setErrorHandler
(ErrorHandler errorHandler) void
setFailover
(boolean failover) Specify whether partition dispatchers should have failover enabled.void
setLoadBalancingStrategy
(LoadBalancingStrategy loadBalancingStrategy) Provide aLoadBalancingStrategy
for partition dispatchers.void
setMessageHandlingTaskDecorator
(MessageHandlingTaskDecorator messageHandlingTaskDecorator) Set aMessageHandlingTaskDecorator
to wrap a message handling task into some addition logic, e.g.void
setThreadFactory
(ThreadFactory threadFactory) Set aThreadFactory
for executors per partitions.void
shutdown()
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 aThreadFactory
for executors per partitions. Defaults to theCustomizableThreadFactory
based on apartition-thread-
prefix.- Parameters:
threadFactory
- theThreadFactory
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.
-
setLoadBalancingStrategy
Provide aLoadBalancingStrategy
for partition dispatchers.- Parameters:
loadBalancingStrategy
- The load balancing strategy implementation.
-
setErrorHandler
- Parameters:
errorHandler
- theErrorHandler
to use.
-
setMessageHandlingTaskDecorator
public void setMessageHandlingTaskDecorator(MessageHandlingTaskDecorator messageHandlingTaskDecorator) Set aMessageHandlingTaskDecorator
to wrap a message handling task into some addition logic, e.g. message channel may provide an interception for its operations.- Parameters:
messageHandlingTaskDecorator
- theMessageHandlingTaskDecorator
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
Description copied from interface:MessageDispatcher
Dispatch the message.- Parameters:
message
- the message.- Returns:
- true if dispatched.
-