fusenapi/server/websocket/internal/logic/mq_consumer.go

54 lines
1.4 KiB
Go
Raw Normal View History

2023-08-07 04:31:31 +00:00
package logic
import (
2023-08-08 04:22:15 +00:00
"context"
2023-08-07 04:31:31 +00:00
"encoding/json"
"fusenapi/constants"
"fusenapi/utils/websocket_data"
"github.com/zeromicro/go-zero/core/logx"
)
// 消费渲染结果数据
type MqConsumerRenderResult struct {
}
2023-08-08 04:22:15 +00:00
func (m *MqConsumerRenderResult) Run(ctx context.Context, data []byte) error {
2023-08-07 04:31:31 +00:00
logx.Info("接收到MqConsumerRenderResult数据:", string(data))
var parseInfo websocket_data.RenderImageNotify
if err := json.Unmarshal(data, &parseInfo); err != nil {
logx.Error("MqConsumerRenderResult data format err:", err)
return nil //不返回错误则就删掉该消息
}
//遍历websocket链接把数据传进去
mapConnPool.Range(func(key, value any) bool {
//断言连接
ws, ok := value.(wsConnectItem)
if !ok {
return true
}
//关闭标识
if ws.isClose {
return true
}
//查询有无该渲染任务
renderId, ok := ws.renderProperty.renderImageTask[parseInfo.TaskId]
if !ok {
return true
}
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: renderId,
Image: parseInfo.Image,
})
//删除对应的需要渲染的图片map
ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
Option: 0, //0删除 1添加
TaskId: parseInfo.TaskId,
RenderId: renderId,
}
//发送数据到out chan
ws.sendToOutChan(b)
return true
})
return nil
}