ws
CI / changes (push) Successful in 1m29s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 35s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 1s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 1s
CI / percutaneous (push) Successful in 21s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 0s
CI / user (push) Successful in 0s
CI / task (push) Successful in 0s
CI / wecom (push) Successful in 0s

This commit is contained in:
2026-10-08 17:53:16 +08:00
parent 93f7b46073
commit 9260e75aa4
2 changed files with 0 additions and 14 deletions
-10
View File
@@ -15,17 +15,14 @@ import (
func PercutaneousAddUser(rpcMgr *wsproxy.RpcClientManager) http.HandlerFunc {
return request.UserReadMiddleware(func(w http.ResponseWriter, r *http.Request) {
logx.Infof("BFF ws handler start, raw url=%s", r.URL.String())
cli, ready := rpcMgr.GetClient()
if !ready {
logx.Error("BFF: rpc client not ready, return 503")
http.Error(w, "rpc service unavailable", http.StatusServiceUnavailable)
return
}
logx.Info("BFF: rpc client ready")
hostCode := r.URL.Query().Get("host_code")
logx.Infof("BFF: get host_code from query, val=%s", hostCode)
if hostCode == "" {
logx.Error("BFF: host_code is empty")
http.Error(w, "missing host_code query param", http.StatusBadRequest)
@@ -34,16 +31,13 @@ func PercutaneousAddUser(rpcMgr *wsproxy.RpcClientManager) http.HandlerFunc {
proxyHandler := wsproxy.NewWsProxyHandler(
func(parentCtx context.Context) (grpc.ClientStream, error) {
logx.Info("BFF: enter grpc stream create callback")
streamCli := percutaneous.NewPercutaneousClient(cli.Conn())
stream, err := streamCli.WsAddUserStream(parentCtx)
if err != nil {
logx.Errorf("BFF: create WsAddUserStream failed, err=%v", err)
return nil, err
}
logx.Info("BFF: grpc stream create SUCCESS")
// =========核心新增:BFF自动发送第一条host_code消息给percutaneous=========
jsonStr := fmt.Sprintf(`{"host_code":"%s"}`, hostCode)
reqMsg := &percutaneous.WsStreamRequest{
RawBody: []byte(jsonStr),
@@ -53,16 +47,12 @@ func PercutaneousAddUser(rpcMgr *wsproxy.RpcClientManager) http.HandlerFunc {
logx.Errorf("BFF: auto send host_code msg failed, err=%v, json=%s", err, jsonStr)
return nil, err
}
logx.Infof("BFF: auto send host_code message success, content=%s", jsonStr)
// =====================================================================
return stream, nil
},
func() protoreflect.ProtoMessage {
return &percutaneous.WsStreamRequest{}
},
)
logx.Info("BFF: start run proxyHandler")
proxyHandler(w, r)
logx.Info("BFF: proxyHandler finished, ws stream closed")
})
}