diff --git a/goctl_template/api/context.tpl b/goctl_template/api/context.tpl index 70f70ff2..ca4b66ff 100644 --- a/goctl_template/api/context.tpl +++ b/goctl_template/api/context.tpl @@ -18,16 +18,14 @@ type ServiceContext struct { {{.middleware}} MysqlConn *gorm.DB AllModels *gmodel.AllModelsGen - RabbitMq map[string]*initalize.QueueItem } func NewServiceContext(c {{.config}}) *ServiceContext { - + initalize.InitRabbitMq(c.SourceRabbitMq, nil) return &ServiceContext{ Config: c, MysqlConn: initalize.InitMysql(c.SourceMysql), AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), - RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), {{.middlewareAssignment}} } } diff --git a/initalize/rabbitmq.go b/initalize/rabbitmq.go index 484da01f..f3a70475 100644 --- a/initalize/rabbitmq.go +++ b/initalize/rabbitmq.go @@ -13,7 +13,12 @@ type QueueItem struct { Queue amqp.Queue } -func InitRabbitMq(url string, config *tls.Config) map[string]*QueueItem { +var mapMq = make(map[string]*QueueItem) + +func InitRabbitMq(url string, config *tls.Config) { + if url == "" { + return + } conn, err := amqp.DialTLS(url, config) if err != nil { log.Fatalf("Failed to connect to RabbitMQ: %v", err) @@ -23,7 +28,6 @@ func InitRabbitMq(url string, config *tls.Config) map[string]*QueueItem { if err != nil { log.Fatalf("Failed to open a channel: %v", err) } - mapMq := make(map[string]*QueueItem) //声明队列 for _, queueName := range constants.MQ_QUEUE_ARR { q, err := ch.QueueDeclare( @@ -44,5 +48,4 @@ func InitRabbitMq(url string, config *tls.Config) map[string]*QueueItem { Queue: q, } } - return mapMq } diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index d58def77..7a5242cd 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -59,6 +59,7 @@ func (w *wsConnectItem) SendToCloudRender(data []byte) { Option: 1, //0删除 1添加 Key: key, } + w.rabbitMq // TODO 数据发送给云渲染服务器 } }