inital commit

This commit is contained in:
2023-11-28 17:15:23 +03:00
commit 030e2f85f5
15 changed files with 620 additions and 0 deletions

30
producer/balancer.go Executable file
View File

@@ -0,0 +1,30 @@
package main
import (
"github.com/segmentio/kafka-go"
)
type SimpleBalancer struct {
N, P int
}
func (ob *SimpleBalancer) Balance(msg kafka.Message, partitions ...int) int {
if len(partitions) == 1 {
return 0
}
if ob.N < 100 {
ob.N++
return partitions[ob.P]
}
if ob.P+1 < len(partitions) {
ob.P++
ob.N = 0
} else {
ob.P = 0
ob.N = 0
}
ob.N++
return partitions[ob.P]
}