Class PartitionHandler
- java.lang.Object
-
- org.springframework.cloud.stream.binder.PartitionHandler
-
public class PartitionHandler extends Object
Utility class to determine if a binding is configured for partitioning (based on the binder properties provided in the constructor) and what partition a message should be delivered to.- Author:
- Patrick Peralta, David Turanski, Gary Russell, Ilayaperumal Gopinathan, Mark Fisher, Marius Bogoevici, Oleg Zhurakousky
-
-
Constructor Summary
Constructors Constructor Description PartitionHandler(org.springframework.expression.EvaluationContext evaluationContext, ProducerProperties properties, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Construct aPartitionHandler
.PartitionHandler(org.springframework.expression.EvaluationContext evaluationContext, ProducerProperties properties, PartitionKeyExtractorStrategy partitionKeyExtractorStrategy, PartitionSelectorStrategy partitionSelectorStrategy)
Deprecated.since 3.0.2.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
determinePartition(org.springframework.messaging.Message<?> message)
Determine the partition to which to send this message.void
setPartitionCount(int partitionCount)
Set the actual partition count (if different to the configured count).
-
-
-
Constructor Detail
-
PartitionHandler
@Deprecated public PartitionHandler(org.springframework.expression.EvaluationContext evaluationContext, ProducerProperties properties, PartitionKeyExtractorStrategy partitionKeyExtractorStrategy, PartitionSelectorStrategy partitionSelectorStrategy)
Deprecated.since 3.0.2. Please use another constructor which allows you to pass an instance of beanFactoryConstruct aPartitionHandler
.- Parameters:
evaluationContext
- evaluation context for binderproperties
- binder propertiespartitionKeyExtractorStrategy
- PartitionKeyExtractor strategypartitionSelectorStrategy
- PartitionSelector strategy
-
PartitionHandler
public PartitionHandler(org.springframework.expression.EvaluationContext evaluationContext, ProducerProperties properties, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Construct aPartitionHandler
.- Parameters:
evaluationContext
- evaluation context for binderproperties
- binder propertiesbeanFactory
- instance of ConfigurableListableBeanFactory- Since:
- 3.0.2
-
-
Method Detail
-
setPartitionCount
public void setPartitionCount(int partitionCount)
Set the actual partition count (if different to the configured count).- Parameters:
partitionCount
- the count.
-
determinePartition
public int determinePartition(org.springframework.messaging.Message<?> message)
Determine the partition to which to send this message.If a partition key extractor class is provided, it is invoked to determine the key. Otherwise, the partition key expression is evaluated to obtain the key value.
If a partition selector class is provided, it will be invoked to determine the partition. Otherwise, if the partition expression is not null, it is evaluated against the key and is expected to return an integer to which the modulo function will be applied, using the
partitionCount
as the divisor. If no partition expression is provided, the key will be passed to the binder partition strategy along with thepartitionCount
. The default partition strategy useskey.hashCode()
, and the result will be the mod of that value.- Parameters:
message
- the message.- Returns:
- the partition
-
-