Behaviour for routing keys to shard names.
route_many/2 is the only required callback: routing is batch-first and
single-key routing is derived from it unless route/2 is implemented.
ctx.shards is the full configured shard list (in configuration order),
including shards in maintenance, so maintenance never remaps keys. Shardex
validates every result: unknown shard names become
{:error, {:unknown_shard, name}}, shards in maintenance become
{:error, :maintenance}, keys missing from the returned map become
{:error, :unassigned}.
A strategy may also be given as a function (key, ctx -> result).
Summary
Callbacks
Builds the strategy state. Runs inside the Coordinator. Default: {:ok, opts}.
Called after add_shard/remove_shard. Default: init(original_opts, shards).
Routes one key. Default: route_many([key], ctx).
Routes many keys at once. Keys missing from the result are :unassigned.
Whether single-key routes emit [:shardex, :route, ...] spans. Default: true.
Types
Callbacks
Builds the strategy state. Runs inside the Coordinator. Default: {:ok, opts}.
Called after add_shard/remove_shard. Default: init(original_opts, shards).
Routes one key. Default: route_many([key], ctx).
Routes many keys at once. Keys missing from the result are :unassigned.
@callback trace?() :: boolean()
Whether single-key routes emit [:shardex, :route, ...] spans. Default: true.