MCPcopy
hub / github.com/segmentio/kafka-go / Hash

Struct Hash

balancer.go:143–151  ·  view source on GitHub ↗

Hash is a Balancer that uses the provided hash function to determine which partition to route messages to. This ensures that messages with the same key are routed to the same partition. The logic to calculate the partition is: hasher.Sum32() % len(partitions) => partition By default, Hash uses

Source from the content-addressed store, hash-verified

141// by the Sarama Producer and ensures that messages produced by kafka-go will
142// be delivered to the same topics that the Sarama producer would be delivered to.
143type Hash struct {
144 rr RoundRobin
145 Hasher hash.Hash32
146
147 // lock protects Hasher while calculating the hash code. It is assumed that
148 // the Hasher field is read-only once the Balancer is created, so as a
149 // performance optimization, reads of the field are not protected.
150 lock sync.Mutex
151}
152
153func (h *Hash) Balance(msg Message, partitions ...int) int {
154 if msg.Key == nil {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected