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

Function NewCustomHashPartitioner

partitioner.go:145–154  ·  view source on GitHub ↗

NewCustomHashPartitioner is a wrapper around NewHashPartitioner, allowing the use of custom hasher. The argument is a function providing the instance, implementing the hash.Hash32 interface. This is to ensure that each partition dispatcher gets its own hasher, to avoid concurrency issues by sharing

(hasher func() hash.Hash32)

Source from the content-addressed store, hash-verified

143// The argument is a function providing the instance, implementing the hash.Hash32 interface. This is to ensure that
144// each partition dispatcher gets its own hasher, to avoid concurrency issues by sharing an instance.
145func NewCustomHashPartitioner(hasher func() hash.Hash32) PartitionerConstructor {
146 return func(topic string) Partitioner {
147 p := new(hashPartitioner)
148 p.random = NewRandomPartitioner(topic)
149 p.hasher = hasher()
150 p.referenceAbs = false
151 p.hashUnsigned = false
152 return p
153 }
154}
155
156// NewCustomPartitioner creates a default Partitioner but lets you specify the behavior of each component via options
157func NewCustomPartitioner(options ...HashPartitionerOption) PartitionerConstructor {

Calls 1

NewRandomPartitionerFunction · 0.85