MCPcopy
hub / github.com/IBM/sarama / NewHashPartitioner

Function NewHashPartitioner

partitioner.go:175–182  ·  view source on GitHub ↗

NewHashPartitioner returns a Partitioner which behaves as follows. If the message's key is nil then a random partition is chosen. Otherwise the FNV-1a hash of the encoded bytes of the message key is used, modulus the number of partitions. This ensures that messages with the same key always end up on

(topic string)

Source from the content-addressed store, hash-verified

173// modulus the number of partitions. This ensures that messages with the same key always end up on the
174// same partition.
175func NewHashPartitioner(topic string) Partitioner {
176 p := new(hashPartitioner)
177 p.random = NewRandomPartitioner(topic)
178 p.hasher = fnv.New32a()
179 p.referenceAbs = false
180 p.hashUnsigned = false
181 return p
182}
183
184// NewReferenceHashPartitioner is like NewHashPartitioner except that it handles absolute values
185// in the same way as the reference Java implementation. NewHashPartitioner was supposed to do

Callers 4

TestHashPartitionerFunction · 0.85

Calls 1

NewRandomPartitionerFunction · 0.85

Tested by 4

TestHashPartitionerFunction · 0.68