1
0
Fork 0
shezmu/example/main.go

53 lines
1.1 KiB
Go
Raw Normal View History

2015-10-14 00:34:59 +00:00
package main
import (
"flag"
"os"
"os/signal"
"strings"
2016-01-10 11:53:55 +00:00
"syscall"
2015-10-14 00:34:59 +00:00
2015-10-14 00:50:43 +00:00
"github.com/localhots/satan"
"github.com/localhots/satan/example/daemons"
"github.com/localhots/satan/example/kafka"
2015-10-27 22:23:39 +00:00
"github.com/localhots/satan/server"
2015-10-23 23:42:00 +00:00
"github.com/localhots/satan/stats"
2015-10-14 00:34:59 +00:00
)
func main() {
var brokers string
flag.StringVar(&brokers, "brokers", "127.0.0.1:9092", "Kafka broker addresses separated by space")
2015-10-14 00:34:59 +00:00
flag.Parse()
kafka.Initialize(strings.Split(brokers, " "))
defer kafka.Shutdown()
2015-10-24 16:25:16 +00:00
statsLogger := stats.NewStdoutLogger(0)
defer statsLogger.Print()
2015-10-23 23:42:00 +00:00
2015-10-27 22:23:39 +00:00
statsServer := stats.NewServer()
server := server.New(6464, statsServer)
server.Start()
2015-10-14 00:50:43 +00:00
s := satan.Summon()
2016-01-10 18:03:00 +00:00
s.Subscriber = kafka.Subscriber{}
2015-10-27 22:23:39 +00:00
s.DaemonStats = stats.NewGroup(statsLogger, statsServer)
2015-10-23 23:42:00 +00:00
2015-10-14 00:50:43 +00:00
s.AddDaemon(&daemons.NumberPrinter{})
s.AddDaemon(&daemons.PriceConsumer{})
2015-10-14 01:11:29 +00:00
s.StartDaemons()
defer s.StopDaemons()
2015-10-14 00:34:59 +00:00
sig := make(chan os.Signal)
2016-01-10 11:53:55 +00:00
signal.Notify(sig, syscall.SIGINT, syscall.SIGHUP)
switch <-sig {
case syscall.SIGHUP:
s.StopDaemons()
s.StartDaemons()
case syscall.SIGINT:
return
}
2015-10-14 00:34:59 +00:00
}