pub trait MessageRouter:
Send
+ Sync
+ Debug {
// Required method
fn route(&self, msg: &OutgoingMessage, partitions: usize) -> usize;
}Expand description
Plug a user-provided routing function in front of MessageRoutingMode. Mirrors
Java’s MessageRouter SPI — when set on the builder, the function decides the
partition for every outgoing message; the configured MessageRoutingMode is
ignored. Use this for affinity routing rules (geo, tenant, schema-keyed) that don’t
fit the partition-key-hash mould.
The callback runs on the send path — keep it fast and non-blocking. The framework
clamps the returned index into [0, partitions) so out-of-range values can’t crash
the producer.
Required Methods§
Sourcefn route(&self, msg: &OutgoingMessage, partitions: usize) -> usize
fn route(&self, msg: &OutgoingMessage, partitions: usize) -> usize
Pick a partition index in [0, partitions) for msg.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".