forked from yangsongbai/infini-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsq.go
executable file
·51 lines (38 loc) · 1007 Bytes
/
nsq.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
package nsq
import (
log "github.com/cihub/seelog"
"github.com/nsqio/nsq/nsqd"
"github.com/huminghe/infini-framework/core/config"
)
type NSQModule struct {
}
func (module NSQModule) Name() string {
return "NSQ"
}
func (module NSQModule) Setup(cfg *config.Config) {
}
var done chan bool = make(chan bool)
var instance *nsqd.NSQD
func (module NSQModule) Start() error {
// Run the embedded nsqd in a go routine
go func() {
// running an nsqd with all of the default options
// (as if you ran it from the command line with no flags)
// is literally these three lines of code. the nsqd
// binary mainly wraps up the handling of command
// line args and does something similar
opts := nsqd.NewOptions()
instance = nsqd.New(opts)
instance.Main()
log.Debug("starting nsq service")
// wait until we are told to continue and exit
<-done
}()
return nil
}
func (module NSQModule) Stop() error {
// tell the nsqd instance to exit
instance.Exit()
done <- true
return nil
}