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
+8 -12
View File
@@ -6,27 +6,23 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
"google.golang.org/grpc"
)
type PushClient struct {
MetaClient
conn *grpc.ClientConn
}
func NewPushClient(client discoveryregistry.SvcDiscoveryRegistry) *PushClient {
return &PushClient{
MetaClient: MetaClient{
client: client,
rpcRegisterName: config.Config.RpcRegisterName.OpenImPushName,
},
func NewPushClient(discov discoveryregistry.SvcDiscoveryRegistry) *PushClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImPushName)
if err != nil {
panic(err)
}
return &PushClient{conn: conn}
}
func (p *PushClient) DelUserPushToken(ctx context.Context, req *push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) {
cc, err := p.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := push.NewPushMsgServiceClient(cc).DelUserPushToken(ctx, req)
resp, err := push.NewPushMsgServiceClient(p.conn).DelUserPushToken(ctx, req)
if err != nil {
return nil, err
}