-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (66 loc) · 2.46 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
package main
import (
"./pkg/relay"
"flag"
"fmt"
"github.com/kingster/go-metrics-statsd"
"github.com/rcrowley/go-metrics"
"github.com/tkanos/gonfig"
"log"
"net"
"os"
"time"
)
type AppConfiguration struct {
RedisEndpoint string
QueuePattern string
KafkaBrokers string
SourceBatchSize int
SinkBatchSize int
ZKConnect []string
Zone string
}
func main() {
configPtr := flag.String("config", "/etc/relayer/relayer.json", "Config File Path ( default /etc/relayer/relayer.json)")
flag.Parse()
configuration := AppConfiguration{}
err := gonfig.GetConf(*configPtr, &configuration)
if err != nil {
panic(err)
}
fmt.Println(`
.▄▄ · ▄▄▄▄▄▄▄▄ ▄▄▌ ▐ ▄▌ ▄▄ • ▄▄▄ .▄▄▄
▐█ ▀. •██ ▀▄ █·▪ ██· █▌▐█▐█ ▀ ▪▀▄.▀·▀▄ █·
▄▀▀▀█▄ ▐█.▪▐▀▀▄ ▄█▀▄ ██▪▐█▐▐▌▄█ ▀█▄▐▀▀▪▄▐▀▀▄
▐█▄▪▐█ ▐█▌·▐█•█▌▐█▌.▐▌▐█▌██▐█▌▐█▄▪▐█▐█▄▄▌▐█•█▌
▀▀▀▀ ▀▀▀ .▀ ▀ ▀█▄▀▪ ▀▀▀▀ ▀▪·▀▀▀▀ ▀▀▀ .▀ ▀
▄▄▄ ▄▄▄ .▄▄▌ ▄▄▄· ▄· ▄▌▄▄▄ .▄▄▄
▀▄ █·▀▄.▀·██• ▐█ ▀█ ▐█▪██▌▀▄.▀·▀▄ █·
▐▀▀▄ ▐▀▀▪▄██▪ ▄█▀▀█ ▐█▌▐█▪▐▀▀▪▄▐▀▀▄
▐█•█▌▐█▄▄▌▐█▌▐▌▐█ ▪▐▌ ▐█▀·.▐█▄▄▌▐█•█▌
.▀ ▀ ▀▀▀ .▀▀▀ ▀ ▀ ▀ • ▀▀▀ .▀ ▀
`)
go metrics.Log(metrics.DefaultRegistry, 30*time.Second, log.New(os.Stdout, "metrics: ", log.Lmicroseconds))
addr, _ := net.ResolveUDPAddr("udp", ":8125")
go statsd.StatsD(metrics.DefaultRegistry, 30*time.Second, "strowger", addr)
relayer := relay.Relayer{
Source: relay.RedisSource{
Endpoint: configuration.RedisEndpoint,
Pattern: configuration.QueuePattern,
},
Sink: relay.KafkaSink{
Brokers: configuration.KafkaBrokers,
},
Options: &relay.Options{
SourceBatchSize: configuration.SourceBatchSize,
SinkBatchSize: configuration.SinkBatchSize,
},
Zone: configuration.Zone,
}
leadership := relay.LeaderElector{
ZKConnect: configuration.ZKConnect,
ElectionNode: fmt.Sprintf("/election/relayer-%s", configuration.Zone),
}
leadership.SetTask(relayer.Run)
leadership.Elect()
}