-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (70 loc) · 1.89 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"net/http"
"os"
"time"
"github.com/harbinzhang/goRainbow/core/module"
"github.com/harbinzhang/goRainbow/core/util"
"go.uber.org/zap"
"github.com/harbinzhang/goRainbow/core/pipeline"
)
func main() {
defer handleExit()
const link string = "http://127.0.0.1:8000/v3/kafka"
const ProduceQueueSize int = 9000
os.Setenv("configPath", "config/config.json")
// Queue init
produceQueue := make(chan string, ProduceQueueSize)
// Prepare count service
countService := &module.CountService{ProduceQueue: produceQueue}
countService.Start()
//prepare logger
logger := util.GetLogger()
pipeline.PrepareLogger()
// Prepare pipeline routines
aliveConsumersMaintainer := &pipeline.AliveConsumersMaintainer{
BurrowURL: link,
ProduceQueue: produceQueue,
CountService: countService,
Logger: logger.With(
zap.String("module", "aliveConsumersMaintainer"),
),
}
aliveTopicsMaintainer := &pipeline.AliveTopicsMaintainer{
BurrowURL: link,
ProduceQueue: produceQueue,
CountService: countService,
Logger: logger.With(
zap.String("module", "aliveTopicsMaintainer"),
),
}
producer := &pipeline.Producer{
ProduceQueue: produceQueue,
CountService: countService,
Logger: logger.With(
zap.String("module", "producer"),
),
}
go producer.Start()
go aliveConsumersMaintainer.Start()
go aliveTopicsMaintainer.Start()
// health_check server
healthCheckHandler := module.HealthChecker(countService)
http.HandleFunc("/health_check", healthCheckHandler)
http.ListenAndServe(":7099", nil)
fmt.Println("goRainbow exited")
countService.Stop()
close(produceQueue)
// exit cleanly
os.Exit(0)
}
func handleExit() {
if e := recover(); e != nil {
if exit, ok := e.(string); ok {
fmt.Fprintln(os.Stderr, exit, "Stopped goRainbow at", time.Now().Format("March 26, 2019 at 1:24pm (PST)"))
os.Exit(1)
}
panic(e) // not an string, bubble up
}
}