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

Method Balance

balancer.go:298–307  ·  view source on GitHub ↗
(msg Message, partitions ...int)

Source from the content-addressed store, hash-verified

296}
297
298func (b Murmur2Balancer) Balance(msg Message, partitions ...int) (partition int) {
299 // NOTE: the murmur2 balancers in java and librdkafka treat a nil key as
300 // non-existent while treating an empty slice as a defined value.
301 if msg.Key == nil && !b.Consistent {
302 return b.random.Balance(msg, partitions...)
303 }
304
305 idx := (murmur2(msg.Key) & 0x7fffffff) % uint32(len(partitions))
306 return partitions[idx]
307}
308
309// Go port of the Java library's murmur2 function.
310// https://github.com/apache/kafka/blob/1.0/clients/src/main/java/org/apache/kafka/common/utils/Utils.java#L353

Callers 1

TestMurmur2BalancerFunction · 0.95

Calls 2

murmur2Function · 0.85
BalanceMethod · 0.65

Tested by 1

TestMurmur2BalancerFunction · 0.76