From f8df7b55b3cb562f4002247b754bea1ddd24d874 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 16:53:50 +0800 Subject: [PATCH 1/7] fix --- server/render/consumer/assemble_render_data.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 8fb6f82b..85fe4079 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -180,7 +180,7 @@ func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo "address": "", "phone": "", "colors": []string{}, - "template_tagid": []string{}, + "template_tagid": []string{"b1a"}, "is_crop": false, "shape": "", "ratio": 0, @@ -222,6 +222,9 @@ func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo url := svcCtx.Config.PythonApi.CombineImageUrl header := make(map[string]string) header["content-type"] = "application/json" + /*f, _ := os.Create("a.txt") + defer f.Close() + f.Write(postData)*/ httpRsp, err := curl.ApiCall(url, "POST", header, bytes.NewReader(postData), 20) if err != nil { logx.Error("failed to combine logo:", err) From b9aa0e6d103e172feaa0a322d1e7d8041c290ece Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 17:31:45 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxyserver/main.go | 66 ++++----------------------------------------- 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/proxyserver/main.go b/proxyserver/main.go index da313c35..066a16d1 100644 --- a/proxyserver/main.go +++ b/proxyserver/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" "io" - "io/fs" + "io/ioutil" "log" "net" "net/http" @@ -15,7 +15,6 @@ import ( "sync" "time" - "github.com/gorilla/websocket" "gopkg.in/yaml.v2" ) @@ -116,8 +115,6 @@ type Backend struct { HttpAddress string Client *http.Client Handler http.HandlerFunc - - Dialer *websocket.Dialer } func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Backend { @@ -145,29 +142,14 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac }, } - dialer := &websocket.Dialer{ - Proxy: http.ProxyFromEnvironment, - NetDial: func(network, addr string) (net.Conn, error) { - return net.Dial(network, addr) - }, - } - // 创建后端服务对象,包含地址和客户端 backend := &Backend{ HttpAddress: httpAddress, Client: client, - Dialer: dialer, } // 创建处理请求的函数 handleRequest := func(w http.ResponseWriter, r *http.Request) { - - if websocket.IsWebSocketUpgrade(r) { - // Handle websocket connections - handleWebSocketProxy(w, r, backend) - return - } - // 解析目标URL,包含了查询参数 targetURL, err := url.Parse(httpAddress + r.URL.String()) if err != nil { @@ -244,7 +226,7 @@ type Result struct { // GetZeroInfo 遍历指定目录,并解析相关信息 func GetZeroInfo(rootDir string) (results []*Result) { - entries, err := os.ReadDir(rootDir) + entries, err := ioutil.ReadDir(rootDir) if err != nil { log.Fatal(err) } @@ -265,7 +247,7 @@ func GetZeroInfo(rootDir string) (results []*Result) { } // findFoldersAndExtractInfo 查找目录并提取信息 -func findFoldersAndExtractInfo(rootDir string, entry fs.DirEntry) (*Result, error) { +func findFoldersAndExtractInfo(rootDir string, entry os.FileInfo) (*Result, error) { var result *Result folderName := entry.Name() @@ -295,7 +277,7 @@ func findFoldersAndExtractInfo(rootDir string, entry fs.DirEntry) (*Result, erro configPath := filepath.Join(path, "etc", folderName+".yaml") routesPath := filepath.Join(path, "internal", "handler", "routes.go") - configContent, err := os.ReadFile(configPath) + configContent, err := ioutil.ReadFile(configPath) if err != nil { return err } @@ -307,7 +289,7 @@ func findFoldersAndExtractInfo(rootDir string, entry fs.DirEntry) (*Result, erro } // 读取路由文件 - routesContent, err := os.ReadFile(routesPath) + routesContent, err := ioutil.ReadFile(routesPath) if err != nil { return err } @@ -352,41 +334,3 @@ func extractPrefixRouteValues(content string) map[string]bool { return prefixPath } - -func handleWebSocketProxy(w http.ResponseWriter, r *http.Request, backend *Backend) { - target := url.URL{Scheme: "ws", Host: backend.HttpAddress, Path: r.URL.Path} - - proxyConn, _, err := backend.Dialer.DialContext(r.Context(), target.String(), nil) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - defer proxyConn.Close() - - upgrader := websocket.Upgrader{} - conn, err := upgrader.Upgrade(w, r, nil) - if err != nil { - return - } - defer conn.Close() - - go transfer(proxyConn, conn) - go transfer(conn, proxyConn) -} - -func transfer(src, dest *websocket.Conn) { - for { - messageType, data, err := src.ReadMessage() - if err != nil { - break - } - - err = dest.WriteMessage(messageType, data) - if err != nil { - break - } - } - - src.Close() - dest.Close() -} From 42193df5052fa2ab927a2b3adfc514e11922a134 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 17:41:36 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=B5=8B=E8=AF=95websocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxyserver/main.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/proxyserver/main.go b/proxyserver/main.go index 066a16d1..05631968 100644 --- a/proxyserver/main.go +++ b/proxyserver/main.go @@ -15,6 +15,7 @@ import ( "sync" "time" + "github.com/gorilla/websocket" "gopkg.in/yaml.v2" ) @@ -115,6 +116,7 @@ type Backend struct { HttpAddress string Client *http.Client Handler http.HandlerFunc + Dialer *websocket.Dialer } func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Backend { @@ -142,14 +144,63 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac }, } + dialer := &websocket.Dialer{ + Proxy: http.ProxyFromEnvironment, + NetDial: func(network, addr string) (net.Conn, error) { + return net.Dial(network, addr) + }, + } + // 创建后端服务对象,包含地址和客户端 backend := &Backend{ HttpAddress: httpAddress, Client: client, + Dialer: dialer, } // 创建处理请求的函数 handleRequest := func(w http.ResponseWriter, r *http.Request) { + + if websocket.IsWebSocketUpgrade(r) { + //todo: 建立websocket的代理 + + target := url.URL{Scheme: "ws", Host: backend.HttpAddress, Path: r.URL.Path} + + var transfer = func(src, dest *websocket.Conn) { + for { + mType, msg, err := src.ReadMessage() + if err != nil { + break + } + + err = dest.WriteMessage(mType, msg) + if err != nil { + break + } + } + + src.Close() + dest.Close() + } + + proxyConn, _, err := backend.Dialer.Dial(target.String(), nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + defer proxyConn.Close() + + upgrader := websocket.Upgrader{} + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + return + } + defer conn.Close() + + go transfer(proxyConn, conn) + go transfer(conn, proxyConn) + } + // 解析目标URL,包含了查询参数 targetURL, err := url.Parse(httpAddress + r.URL.String()) if err != nil { From 0c4f33b486c7a0d6598890c7aa749efb9758cb2d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 18:12:07 +0800 Subject: [PATCH 4/7] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 6e6f74ae..1aadd993 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -99,10 +99,10 @@ func (w *wsConnectItem) renderImage(data []byte) { d, _ := json.Marshal(tmpData) //发送给对应的流水线组装数据 if err := w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, d); err != nil { - logx.Error("发送渲染任务数据到MQ失败:", string(data), "err:", err) + logx.Error("发送渲染任务数据到MQ失败:", string(d), "err:", err) return } - logx.Info("发送渲染数据到rabbitmq成功:", string(data)) + logx.Info("发送渲染数据到rabbitmq成功:", string(d)) } // 操作连接中渲染任务的增加/删除 From d85c39327c44badea8696fe678c38e0b9ea25d31 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 18:18:00 +0800 Subject: [PATCH 5/7] fix --- .../render/consumer/assemble_render_data.go | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 85fe4079..5334db5b 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -40,11 +40,13 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { } val := ctx.Value("svcctx") if val == nil { - return errors.New("svcctx is nil") + logx.Error("svcctx is nil") + return nil //不返回错误就删除消息 } svcCtx, ok := val.(*svc.ServiceContext) if !ok { - return errors.New("svcctx is nil!!") + logx.Error("svcctx is nil!!") + return nil //不返回错误就删除消息 } rabbitmq := initalize.RabbitMqHandle{} //获取模板(产品第一个sku的模板) @@ -52,10 +54,10 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("template info is not found") - return nil + return nil //不返回错误就删除消息 } logx.Error("failed to get template info:", err) - return err + return nil //不返回错误就删除消息 } combineImage := "" //刀版图 combineHash := hash.JsonHashKey(parseInfo) //区别于云渲染的taskid,这个用获取刀版图缓存 @@ -63,13 +65,13 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { resource, err := svcCtx.AllModels.FsResource.FindOneById(ctx, combineHash) if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("failed to get resource :", err) - return err + return nil //不返回错误就删除消息 } //如果不存在,则请求生成刀版图 if errors.Is(err, gorm.ErrRecordNotFound) { combineImage, err = getCombineImage(ctx, svcCtx, parseInfo, productTemplate, combineHash) if err != nil { - return err + return nil //不返回错误就删除消息 } } else { combineImage = *resource.ResourceUrl @@ -79,10 +81,10 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId) - return nil + return nil //不返回错误就删除消息 } logx.Error("failed to get element list,", err) - return err + return nil //不返回错误就删除消息 } //组装数据 refletion := -1 @@ -94,7 +96,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { if element.Mode != nil && *element.Mode != "" { if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil { logx.Error("faile to parse element mode json:", err) - return err + return nil //不返回错误就删除消息 } } tempData := make([]map[string]interface{}, 0, 3) @@ -154,7 +156,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { b, _ := json.Marshal(sendData) if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil { logx.Error("发送渲染组装数据到rabbitmq失败:", err) - return err + return nil //不返回错误就删除消息 } logx.Info("发送渲染组装数据到unity成功") return nil From 4ec7bc6106d56254dc6b93c27e8373824feda012 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 18:30:02 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BB=A3=E7=90=86=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxyserver/main.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/proxyserver/main.go b/proxyserver/main.go index 05631968..811f6476 100644 --- a/proxyserver/main.go +++ b/proxyserver/main.go @@ -164,17 +164,19 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac if websocket.IsWebSocketUpgrade(r) { //todo: 建立websocket的代理 - target := url.URL{Scheme: "ws", Host: backend.HttpAddress, Path: r.URL.Path} + target := url.URL{Scheme: "ws", Host: strings.Split(backend.HttpAddress, "//")[1], Path: r.URL.Path} var transfer = func(src, dest *websocket.Conn) { for { mType, msg, err := src.ReadMessage() if err != nil { + log.Println(err) break } err = dest.WriteMessage(mType, msg) if err != nil { + log.Println(err) break } } @@ -183,22 +185,33 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac dest.Close() } - proxyConn, _, err := backend.Dialer.Dial(target.String(), nil) + header := r.Header.Clone() + // log.Println(target.String()) + header.Del("Sec-Websocket-Extensions") + header.Del("Upgrade") + header.Del("Sec-Websocket-Key") + header.Del("Sec-Websocket-Version") + header.Del("Connection") + // header.Del("Origin") + proxyConn, _, err := backend.Dialer.Dial(target.String(), header) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - defer proxyConn.Close() + // defer proxyConn.Close() - upgrader := websocket.Upgrader{} + upgrader := websocket.Upgrader{ + CheckOrigin: func(r *http.Request) bool { return true }, + } conn, err := upgrader.Upgrade(w, r, nil) if err != nil { return } - defer conn.Close() + // defer conn.Close() go transfer(proxyConn, conn) - go transfer(conn, proxyConn) + // go transfer(conn, proxyConn) + return } // 解析目标URL,包含了查询参数 From c7cf72030a1d4e10e1506dfe916d48cb17976f4a Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 19:18:54 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_all_server.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_all_server.sh b/run_all_server.sh index 6d8a2033..fc8318dc 100755 --- a/run_all_server.sh +++ b/run_all_server.sh @@ -22,6 +22,8 @@ run_server() { cd - > /dev/null } +find /tmp/go-build* -mmin +5 -delete + # 列出所有服务器目录 server_dirs=() # 初始化一个空数组