CompositeAggregateIdSharding

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"

See also

Throws

if no sharding strategy is registered for the aggregate type

Constructors

Link copied to clipboard
constructor(registrar: Map<NamedAggregate, AggregateIdSharding>)

Functions

Link copied to clipboard
open override fun sharding(aggregateId: AggregateId): String

Determines the shard for the given aggregate ID.