2015-10-14 00:34:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2015-10-17 00:42:27 +00:00
|
|
|
"strings"
|
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"
|
2015-10-17 01:10:16 +00:00
|
|
|
"github.com/localhots/satan/example/kafka"
|
2015-10-14 00:34:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var debug bool
|
2015-10-17 00:42:27 +00:00
|
|
|
var brokers string
|
|
|
|
|
2015-10-14 00:34:59 +00:00
|
|
|
flag.BoolVar(&debug, "v", false, "Verbose mode")
|
2015-10-17 01:10:16 +00:00
|
|
|
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()
|
2015-10-17 00:42:27 +00:00
|
|
|
|
|
|
|
log.SetOutput(ioutil.Discard)
|
|
|
|
if debug {
|
|
|
|
log.SetOutput(os.Stderr)
|
2015-10-14 00:34:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-17 01:10:16 +00:00
|
|
|
kafka.Initialize(strings.Split(brokers, " "))
|
|
|
|
defer kafka.Shutdown()
|
2015-10-17 00:42:27 +00:00
|
|
|
|
2015-10-14 00:50:43 +00:00
|
|
|
s := satan.Summon()
|
2015-10-17 01:10:16 +00:00
|
|
|
s.SubscribeFunc = kafka.MakeStream
|
2015-10-14 00:50:43 +00:00
|
|
|
s.AddDaemon(&daemons.NumberPrinter{})
|
2015-10-17 00:42:27 +00:00
|
|
|
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)
|
2015-10-14 00:36:23 +00:00
|
|
|
signal.Notify(sig, os.Interrupt)
|
2015-10-14 01:17:22 +00:00
|
|
|
<-sig
|
2015-10-14 00:34:59 +00:00
|
|
|
}
|