package main

import (
	"context"
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/service"
	"microGame/app/mq/cmd/rabbitmq/internal/mqs"
	"microGame/app/mq/cmd/rabbitmq/internal/svc"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
	"microGame/app/mq/cmd/rabbitmq/internal/config"
)

var configFile = flag.String("f", "etc/rabbitmq-api.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()

	//ctx := svc.NewServiceContext(c)
	//handler.RegisterHandlers(server, ctx)
	svcCtx := svc.NewServiceContext(c)
	mqs.InitMq(svcCtx)
	//handler.RegisterHandlers(server, svcCtx)
	ctx := context.Background()
	serviceGroup := service.NewServiceGroup()
	defer serviceGroup.Stop()

	for _, mq := range mqs.Consumers(c, ctx, svcCtx) {
		serviceGroup.Add(mq)
	}

	fmt.Printf("Starting rabbitmq server at %s:%d...\n", c.Host, c.Port)
	serviceGroup.Start()
}
