CompositeAggregateIdSharding
class CompositeAggregateIdSharding(registrar: Map<NamedAggregate, AggregateIdSharding>) : AggregateIdSharding
Composite sharding implementation that routes aggregates based on their type.
This class maintains a registry of sharding strategies mapped to specific named aggregates. When sharding an aggregate ID, it looks up the appropriate sharding strategy based on the aggregate's name and type, then delegates the sharding decision to that strategy.
This allows different aggregate types to use different sharding algorithms while maintaining a unified interface.
Example usage:
val orderSharding = SingleAggregateIdSharding("order-node")
val userSharding = SingleAggregateIdSharding("user-node")
val registrar = mapOf(
NamedAggregate("order", "OrderAggregate") to orderSharding,
NamedAggregate("user", "UserAggregate") to userSharding
)
val compositeSharding = CompositeAggregateIdSharding(registrar)
val shard = compositeSharding.sharding(orderAggregateId) // Returns "order-node"Content copied to clipboard
See also
Throws
if no sharding strategy is registered for the aggregate type