2026-03-14 10:02:49 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"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/rabbitmq"
|
|
|
|
|
|
_ "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)
|
|
|
|
|
|
|
|
|
|
|
|
// 提前初始化实例队列名,确保全局唯一
|
|
|
|
|
|
baseQueue := g.Cfg().MustGet(ctx, "rabbitmq.responseQueue", "ragflow.response.queue").String()
|
|
|
|
|
|
instanceQueue := rabbitmq.GetInstanceQueueName(baseQueue)
|
|
|
|
|
|
glog.Infof(ctx, "🔧 实例队列名已初始化: %s", instanceQueue)
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化Consul配置监听(咨询方向配置)
|
|
|
|
|
|
service.InitConsulWatcher(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
// 路由注册(common/http init() 已异步启动服务器,这里注册路由不影响)
|
|
|
|
|
|
http.RouteRegister([]interface{}{
|
|
|
|
|
|
controller.Health,
|
|
|
|
|
|
controller.Archive,
|
|
|
|
|
|
controller.CustomerServiceAccount,
|
|
|
|
|
|
controller.Data,
|
|
|
|
|
|
controller.DataStatistics,
|
|
|
|
|
|
controller.Product,
|
|
|
|
|
|
controller.Speechcraft,
|
|
|
|
|
|
controller.Websocket,
|
|
|
|
|
|
controller.Webhook,
|
|
|
|
|
|
controller.RAGFlowConfig,
|
|
|
|
|
|
controller.RAGFlow, // RAGFlow HTTP处理接口(从message迁移)
|
|
|
|
|
|
controller.XiaohongshuController, // 小红书Webhook接口
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-03-31 14:44:14 +08:00
|
|
|
|
//// 初始化消费者管理器并注册所有消费者
|
|
|
|
|
|
//mgr := rabbitmq.NewConsumerManager(ctx)
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 注册响应消费者
|
|
|
|
|
|
//responseConsumer := service.NewResponseConsumer(ctx)
|
|
|
|
|
|
//mgr.Register("响应消费者", responseConsumer.Start, responseConsumer.Stop)
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 注册追问消费者
|
|
|
|
|
|
//followUpConsumer := service.NewFollowUpConsumer(ctx)
|
|
|
|
|
|
//mgr.Register("追问消费者", followUpConsumer.Start, followUpConsumer.Stop)
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 注册会话归档消费者
|
|
|
|
|
|
//sessionArchiveConsumer := service.NewSessionArchiveConsumer(ctx)
|
|
|
|
|
|
//mgr.Register("会话归档消费者", sessionArchiveConsumer.Start, sessionArchiveConsumer.Stop)
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 注册延时落库消费者
|
|
|
|
|
|
//delayedFlushConsumer := service.NewDelayedFlushConsumer(ctx)
|
|
|
|
|
|
//mgr.Register("延时落库消费者", delayedFlushConsumer.Start, delayedFlushConsumer.Stop)
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 初始化并启动所有消费者
|
|
|
|
|
|
//if err := mgr.Init(); err != nil {
|
|
|
|
|
|
// glog.Fatalf(ctx, "消费者管理器初始化失败: %v", err)
|
|
|
|
|
|
//}
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 初始化 ES 客户端
|
|
|
|
|
|
//if !g.Cfg().MustGet(ctx, "elasticsearch").IsEmpty() {
|
|
|
|
|
|
// if err := elasticsearch.Init(ctx); err != nil {
|
|
|
|
|
|
// glog.Warningf(ctx, "ES 初始化失败(月度归档功能不可用): %v", err)
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
//
|
|
|
|
|
|
//// 启动月度归档定时任务
|
|
|
|
|
|
//if !g.Cfg().MustGet(ctx, "mongo").IsEmpty() && !g.Cfg().MustGet(ctx, "elasticsearch").IsEmpty() {
|
|
|
|
|
|
// service.ArchiveService.StartCron(ctx)
|
|
|
|
|
|
//}
|
2026-03-14 10:02:49 +08:00
|
|
|
|
|
|
|
|
|
|
// 监听系统信号,支持 Ctrl+C 优雅退出
|
|
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
<-quit
|
|
|
|
|
|
|
|
|
|
|
|
glog.Info(ctx, "收到停止信号,正在关闭服务...")
|
|
|
|
|
|
|
|
|
|
|
|
// 停止所有消费者并关闭RabbitMQ连接
|
2026-03-31 14:44:14 +08:00
|
|
|
|
//mgr.Stop()
|
2026-03-14 10:02:49 +08:00
|
|
|
|
|
|
|
|
|
|
glog.Info(ctx, "customerservice 服务已停止")
|
|
|
|
|
|
}
|