-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (66 loc) · 1.37 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 (
"flag"
"fmt"
"log"
"github.com/chenyoufu/yfstream/alert"
"github.com/chenyoufu/yfstream/cook"
"github.com/chenyoufu/yfstream/dump"
"github.com/chenyoufu/yfstream/g"
"github.com/chenyoufu/yfstream/pull"
"os"
"runtime"
)
func input(out chan<- string) {
var kafkaPCs = pull.InitKafkaPCS()
for {
for _, pc := range kafkaPCs {
select {
case msg := <-pc.Messages():
b, err := pull.SemiCooKafkaMsg(msg)
if err != nil {
break
}
out <- string(b)
default:
}
}
}
}
func filter(in <-chan string, outC ...chan<- string) {
var cooker = cook.InitCooker()
for msg := range in {
b, err := cooker.Cook(msg)
if err != nil {
continue
}
//output cooked message to all out channels
for i, c := range outC {
select {
case c <- string(b):
default:
log.Printf("Length Channel %d: %d, Send failed!\n", i, len(outC))
}
}
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
cfg := flag.String("c", "cfg.json", "configuration file")
version := flag.Bool("v", false, "show version")
flag.Parse()
if *version {
fmt.Println(g.VERSION)
os.Exit(0)
}
g.ParseConfig(*cfg)
fmt.Println(g.Config())
var pipeC = make(chan string, 64)
var alertC = make(chan string, 64)
var esC = make(chan string, 64)
go input(pipeC)
go filter(pipeC, alertC, esC)
go alert.Alerter(alertC)
go dump.Dump2ES(esC)
select {}
}