func main() { flag.StringVar(&myId, "id", "", "cluster id, typically a consuming service name") flag.StringVar(&topic, "topic", "", "topic to consume") flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Printf("Unable to create cpuprofile file: %v, moving on\n", err) } else { pprof.StartCPUProfile(f) defer dumpCPUProfile() c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { <-c dumpCPUProfile() os.Exit(0) }() } } log.V(2).Printf("Identified brokers: %v\n", kafkas) server, err := comm.Listen(":4987") if err != nil { log.Printf("Unable to listen on port :4987: %v", err) os.Exit(1) } _, consumers := newConsumer() for _, consumer := range consumers { go handleConsumer(consumer) } go func() { for message := range blackHole.inbox { log.V(2).Printf("Got message in blackhole: %v\n", message) go func(message messages.Message) { log.V(2).Printf("Gonna re-send message from blackhole: %v\n", message) nextRoundRobinClient().inbox <- message }(message) } }() log.Println("Listening on port :4987") for { conn, err := server.Accept() if err != nil { log.Printf("Unable to accept connection: %v", err) continue } go handleClient(conn) } }
func TestMain(m *testing.M) { err := retry(func() error { return fanout.Ping(fanouts) }) if err != nil { log.Println("Unable to ping fanout :(") os.Exit(1) } os.Exit(m.Run()) }
func retryCustom(times int, interval time.Duration, fn func() error) (err error) { for i := 0; i < times; i++ { err = fn() if err == nil { return } log.Printf("Got error: %v, retrying..\n", err) time.Sleep(interval) } log.Println("Gave up :(") return }
func dumpCPUProfile() { log.Println("Dumping cpu profile") pprof.StopCPUProfile() }