grpc conn reuse

This commit is contained in:
wangchuxiao
2023-05-30 16:15:11 +08:00
parent 1b109964ff
commit 85bf1f44e0
20 changed files with 160 additions and 267 deletions
+9 -8
View File
@@ -14,22 +14,23 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
)
func NewThird(c discoveryregistry.SvcDiscoveryRegistry) *Third {
return &Third{c: c}
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
panic(err)
}
return &Third{conn: conn}
}
type Third struct {
c discoveryregistry.SvcDiscoveryRegistry
conn *grpc.ClientConn
}
func (o *Third) client(ctx context.Context) (third.ThirdClient, error) {
conn, err := o.c.GetConn(ctx, config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
return nil, err
}
return third.NewThirdClient(conn), nil
return third.NewThirdClient(o.conn), nil
}
func (o *Third) ApplyPut(c *gin.Context) {