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)
| 173 | // modulus the number of partitions. This ensures that messages with the same key always end up on the |
| 174 | // same partition. |
| 175 | func 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 |