main.go
1.0 KB
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
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/log"
_ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/consumer"
)
func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
go func() {
logs.Info("应用启动")
beego.Run()
}()
consumerRun := consumer.NewRuner()
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
if err := consumerRun.InitConsumer(); err != nil {
logs.Error("启动kafka消息消费者失败:%s", err)
}
consumerRun.Start(ctx)
wg.Done()
}()
go func() {
<-consumerRun.IsReady()
logs.Info("Sarama consumer up and running!...")
}()
for {
select {
case <-sigs:
cancel()
wg.Wait()
return
default:
}
}
}