main.go 973 字节
package main

import (
	"context"
	"os"
	"os/signal"
	"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()

	if err := consumerRun.InitConsumer(); err != nil {
		logs.Error("启动kafka消息消费者失败:%s", err)
	}

	go func() {
		consumerRun.Start(ctx)
	}()
	go func() {
		<-consumerRun.IsReady()
		logs.Info("Sarama consumer up and running!...")
	}()
	for {
		select {
		case <-sigs:
			cancel()
			return
		default:
		}
	}
}