Browse Source

feature(rpcx): rpcx版本升级1.8.0

ZZH-wl 2 years ago
parent
commit
6b9eef883f

+ 1 - 6
opms_admin/app/service/context.go

@@ -10,7 +10,6 @@ import (
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/os/glog"
 	"github.com/gogf/gf/util/gconv"
 
 	"dashoo.cn/micro/app/dao"
@@ -39,11 +38,7 @@ func (c *contextService) Init(ctx context.Context) (*contextService, error) {
 	if err != nil {
 		return nil, myerrors.MicroCallError(err.Error())
 	}
-	reqMethod, err := micro_srv.GetReqMethod(ctx)
-	if err != nil {
-		return nil, myerrors.MicroCallError(err.Error())
-	}
-	glog.Info("Received " + reqMethod + " request @ " + tenant)
+
 	c.Tenant = tenant
 	c.CxtUser = nil
 	if !micro_srv.IsAuthExclude(ctx) {

+ 1 - 4
opms_admin/go.mod

@@ -5,15 +5,12 @@ go 1.16
 require (
 	dashoo.cn/common_definition v0.0.0
 	dashoo.cn/opms_libary v0.0.0
-	github.com/go-redis/redis/v8 v8.11.5 // indirect
 	github.com/gogf/gf v1.16.9
 	github.com/mssola/user_agent v0.5.3
-	github.com/smallnest/rpcx v1.6.10
-	github.com/stretchr/testify v1.7.1 // indirect
+	github.com/smallnest/rpcx v1.8.0
 	golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 // indirect
 	golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
 	golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
-	gopkg.in/yaml.v3 v3.0.0 // indirect
 )
 
 replace dashoo.cn/opms_libary => ../opms_libary

+ 3 - 3
opms_libary/go.mod

@@ -6,9 +6,9 @@ require (
 	dashoo.cn/common_definition v0.0.0
 	github.com/gogf/gf v1.16.9
 	github.com/mojocn/base64Captcha v1.3.5
-	github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
-	github.com/smallnest/rpcx v1.6.10
-	go.opentelemetry.io/otel/internal/metric v0.27.0 // indirect
+	github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
+	github.com/rpcxio/rpcx-consul v0.0.0-20220730062257-1ff0472e730f
+	github.com/smallnest/rpcx v1.8.0
 )
 
 replace dashoo.cn/common_definition => code.dashoo.cn/dashoo/micro_common_definition.git v0.0.0-20220507071646-3d858a040d5e

+ 22 - 12
opms_libary/micro_srv/micro_srv.go

@@ -10,9 +10,20 @@ import (
 	"dashoo.cn/opms_libary/request"
 	"encoding/json"
 	"errors"
+	"github.com/gogf/gf/encoding/gbase64"
+	"github.com/gogf/gf/encoding/gjson"
 	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/net/ghttp"
+	"github.com/gogf/gf/text/gstr"
 	"github.com/gogf/gf/util/gconv"
 	"github.com/rcrowley/go-metrics"
+	consulclient "github.com/rpcxio/rpcx-consul/client"
+	"github.com/rpcxio/rpcx-consul/serverplugin"
+	"github.com/smallnest/rpcx/client"
+	"github.com/smallnest/rpcx/protocol"
+	"github.com/smallnest/rpcx/server"
+	"github.com/smallnest/rpcx/share"
 	"io/ioutil"
 	"net"
 	"os"
@@ -20,17 +31,6 @@ import (
 	"strconv"
 	"strings"
 	"time"
-
-	"github.com/gogf/gf/encoding/gbase64"
-	"github.com/gogf/gf/encoding/gjson"
-	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/net/ghttp"
-	"github.com/gogf/gf/text/gstr"
-	"github.com/smallnest/rpcx/client"
-	"github.com/smallnest/rpcx/protocol"
-	"github.com/smallnest/rpcx/server"
-	"github.com/smallnest/rpcx/serverplugin"
-	"github.com/smallnest/rpcx/share"
 )
 
 // InitMicroSrvClient 获取微服务客户端,arg为可选参数,若有必须是两个,分别是:reg string, serverAddr string
@@ -52,7 +52,8 @@ func InitMicroSrvClient(serviceName, key string, args ...string) (c client.XClie
 	} else {
 		if reg == "consul" { // 服务发现使用consul
 			//d, _ := etcd_client.NewEtcdV3Discovery(srvName, serviceName, []string{etcdAddr}, nil)
-			d, _ := client.NewConsulDiscovery(srvName, serviceName, []string{etcdAddr}, nil)
+			d, _ := consulclient.NewConsulDiscovery(srvName, serviceName, []string{etcdAddr}, nil)
+			//d, _ := client.NewConsulDiscovery(srvName, serviceName, []string{etcdAddr}, nil)
 			c = client.NewXClient(serviceName, client.Failover, client.RoundRobin, d, client.DefaultOption)
 			return c
 		}
@@ -180,11 +181,20 @@ func streamHandler(conn net.Conn, args *share.StreamServiceArgs) {
 
 }
 
+func getTenant(msg *protocol.Message) string {
+	var tenant string
+	if msg.Metadata != nil {
+		tenant = msg.Metadata["tenant"]
+	}
+	return tenant
+}
+
 // HandleAuth 处理Auth认证
 func HandleAuth(ctx context.Context, req *protocol.Message, token string, authExcludePaths []string) error {
 	path := "/" + req.ServicePath + "/" + req.ServiceMethod
 	//g.Log().Info("reqPath: ", path)
 	//g.Log().Info("token: ", token)
+	g.Log().Info("Received " + path + " request @ " + getTenant(req))
 
 	if authPath(path, authExcludePaths) {
 		req.Metadata["authExclude"] = "false"

+ 2 - 8
opms_parent/app/service/context.go

@@ -2,10 +2,8 @@ package service
 
 import (
 	"context"
-	"dashoo.cn/opms_libary/myerrors"
-	"github.com/gogf/gf/os/glog"
-
 	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/myerrors"
 	"dashoo.cn/opms_libary/request"
 )
 
@@ -30,11 +28,7 @@ func (c *ContextService) Init(ctx context.Context) (*ContextService, error) {
 	if err != nil {
 		return nil, myerrors.MicroCallError(err.Error())
 	}
-	reqMethod, err := micro_srv.GetReqMethod(ctx)
-	if err != nil {
-		return nil, myerrors.MicroCallError(err.Error())
-	}
-	glog.Info("Received " + reqMethod + " request @ " + tenant)
+
 	c.Tenant = tenant
 	c.CxtUser = nil
 	if !micro_srv.IsAuthExclude(ctx) {

+ 1 - 1
opms_parent/config/config.toml

@@ -10,7 +10,7 @@
 
 # 微服务注册中心配置
 [service_registry]
-    registry = "peer2peer" # consul 或 peer2peer
+    registry = "consul" # consul 或 peer2peer
     server-addr = "127.0.0.1:8500"
 
 # 数据库连接

+ 1 - 2
opms_parent/go.mod

@@ -6,10 +6,9 @@ require (
 	dashoo.cn/common_definition v0.0.0
 	dashoo.cn/opms_libary v0.0.0
 	github.com/360EntSecGroup-Skylar/excelize v1.4.1
-	github.com/go-redis/redis/v8 v8.11.5 // indirect
 	github.com/gogf/gf v1.16.9
 	github.com/shopspring/decimal v1.3.1
-	github.com/smallnest/rpcx v1.6.10
+	github.com/smallnest/rpcx v1.8.0
 	github.com/stretchr/testify v1.8.0 // indirect
 	golang.org/x/crypto v0.5.0 // indirect
 	golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect