-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
48 lines (39 loc) · 1.04 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
/* Copyright (c) 2018, joy.zhou <chowyu08@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
*/
package main
import (
"os"
"os/signal"
"runtime"
"go.uber.org/zap"
"github.com/fhmq/rhmq/broker"
"github.com/fhmq/rhmq/logger"
)
var (
log = logger.Get().Named("main")
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
config, err := broker.ConfigureConfig(os.Args[1:])
if err != nil {
log.Fatal("configure broker config error: ", zap.Error(err))
}
b, err := broker.NewBroker(config)
if err != nil {
log.Fatal("New Broker error: ", zap.Error(err))
}
b.Start()
s := waitForSignal()
log.Info("signal received, broker closed.", zap.String("singal", s.String()))
}
func waitForSignal() os.Signal {
signalChan := make(chan os.Signal, 1)
defer close(signalChan)
signal.Notify(signalChan, os.Kill, os.Interrupt)
s := <-signalChan
signal.Stop(signalChan)
return s
}