67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package main
|
||
|
||
import (
|
||
"context"
|
||
"customer-server/consts/public"
|
||
"customer-server/controller"
|
||
"customer-server/service"
|
||
"os"
|
||
"os/signal"
|
||
"syscall"
|
||
|
||
"gitea.com/red-future/common/http"
|
||
"gitea.com/red-future/common/jaeger"
|
||
"gitea.com/red-future/common/utils"
|
||
gmq "github.com/bjang03/gmq/core/gmq"
|
||
"github.com/bjang03/gmq/mq"
|
||
"github.com/bjang03/gmq/types"
|
||
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
|
||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/gogf/gf/v2/os/glog"
|
||
)
|
||
|
||
func main() {
|
||
ctx := context.Background()
|
||
defer jaeger.ShutDown(ctx)
|
||
|
||
// 路由注册(common/http init() 已异步启动服务器,这里注册路由不影响)
|
||
http.RouteRegister([]interface{}{
|
||
controller.Account,
|
||
controller.ScriptedSpeech,
|
||
controller.AccountWebsocket,
|
||
controller.AccountHttp,
|
||
})
|
||
|
||
if err := utils.InitGseTool(ctx); err != nil {
|
||
g.Log().Error(ctx, "gse 分词工具初始化失败:", err)
|
||
}
|
||
|
||
gmq.GmqRegister(public.GmqMsgPluginsName, &mq.NatsConn{
|
||
NatsConfig: mq.NatsConfig{
|
||
Addr: g.Cfg().MustGet(ctx, "nats.default.addr").String(),
|
||
Port: g.Cfg().MustGet(ctx, "nats.default.port").String(),
|
||
},
|
||
})
|
||
if err := gmq.GetGmq(public.GmqMsgPluginsName).GmqSubscribe(ctx, &mq.NatsSubMessage{
|
||
SubMessage: types.SubMessage{
|
||
Topic: public.AccountFollowupTopic,
|
||
ConsumerName: public.AccountFollowupConsumer,
|
||
AutoAck: public.AccountFollowupAck,
|
||
FetchCount: public.AccountFollowupCount,
|
||
HandleFunc: service.AccountWebSocket.AccountMsg,
|
||
},
|
||
IsDelayMsg: true,
|
||
}); err != nil {
|
||
return
|
||
}
|
||
|
||
// 监听系统信号,支持 Ctrl+C 优雅退出
|
||
quit := make(chan os.Signal, 1)
|
||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||
<-quit
|
||
|
||
glog.Info(ctx, "正在关闭服务...")
|
||
|
||
}
|