From 25eabde3f69535bfb11ce8dd450912f2b0774b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98hanzhixiao=E2=80=99?= <‘709674996@qq.com’> Date: Thu, 13 Jul 2023 17:04:10 +0800 Subject: [PATCH] fix conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ‘hanzhixiao’ <‘709674996@qq.com’> --- cmd/openim-api/main.go | 1 + config/config.yaml | 6 +++--- internal/rpc/msg/server.go | 3 +++ pkg/common/cmd/rpc.go | 1 + pkg/rpcclient/msg.go | 35 ++++++++++++++++++----------------- pkg/startrpc/start.go | 1 + 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/cmd/openim-api/main.go b/cmd/openim-api/main.go index b80460990..c91445388 100644 --- a/cmd/openim-api/main.go +++ b/cmd/openim-api/main.go @@ -56,6 +56,7 @@ func startPprof() { } func run(port int) error { + port = 10002 if port == 0 { return fmt.Errorf("port is empty") } diff --git a/config/config.yaml b/config/config.yaml index 07d46957e..cbbcf9e18 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -23,9 +23,9 @@ zookeeper: password: #密码 mysql: - address: [ 127.0.0.1:13306 ] #目前仅支持单机 + address: [ 127.0.0.1:3306 ] #目前仅支持单机 username: root #用户名 - password: openIM123 #密码 + password: #密码 database: openIM_v3 #不建议修改 maxOpenConn: 1000 #最大连接数 maxIdleConn: 100 #最大空闲连接数 @@ -42,7 +42,7 @@ mongo: maxPoolSize: 100 redis: - address: [ 127.0.0.1:16379 ] # + address: [ 127.0.0.1:6379 ] # username: #only redis version 6.0+ need username password: openIM123 #密码 diff --git a/internal/rpc/msg/server.go b/internal/rpc/msg/server.go index 3289a4b47..cf50dfb9f 100644 --- a/internal/rpc/msg/server.go +++ b/internal/rpc/msg/server.go @@ -81,6 +81,9 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e groupRpcClient := rpcclient.NewGroupRpcClient(client) friendRpcClient := rpcclient.NewFriendRpcClient(client) mysql, err := relation.NewGormDB() + if err != nil { + return err + } msgMysModel := relation.NewChatLogGorm(mysql) msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel, msgMysModel) s := &msgServer{ diff --git a/pkg/common/cmd/rpc.go b/pkg/common/cmd/rpc.go index 239858764..0c94b2b78 100644 --- a/pkg/common/cmd/rpc.go +++ b/pkg/common/cmd/rpc.go @@ -45,6 +45,7 @@ func (a *RpcCmd) StartSvr( name string, rpcFn func(discov discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, ) error { + a.port = 10030 if a.GetPortFlag() == 0 { return errors.New("port is required") } diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index 89549681c..029e16e47 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -121,9 +121,10 @@ func newSessionTypeConf() map[int32]int32 { } type Message struct { - conn grpc.ClientConnInterface - Client msg.MsgClient - discov discoveryregistry.SvcDiscoveryRegistry + conn grpc.ClientConnInterface + Client msg.MsgClient + discov discoveryregistry.SvcDiscoveryRegistry + userClient user.UserClient } func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message { @@ -132,7 +133,20 @@ func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message { panic(err) } client := msg.NewMsgClient(conn) - return &Message{discov: discov, conn: conn, Client: client} + conn, err = discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName) + if err != nil { + panic(err) + } + userClient := user.NewUserClient(conn) + return &Message{discov: discov, conn: conn, Client: client, userClient: userClient} +} + +func (m *Message) GetAllUserID(ctx context.Context, req *user.GetAllUserIDReq) (*user.GetAllUserIDResp, error) { + resp, err := m.userClient.GetAllUserID(ctx, req) + if err != nil { + return nil, err + } + return resp, nil } type MessageRpcClient Message @@ -265,16 +279,3 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error { return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...) } - -func (m *Message) GetAllUserID(ctx context.Context, req *user.GetAllUserIDReq) (*user.GetAllUserIDResp, error) { - conn, err := m.discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName) - if err != nil { - panic(err) - } - client := user.NewUserClient(conn) - resp, err := client.GetAllUserID(ctx, req) - if err != nil { - return nil, err - } - return resp, nil -} diff --git a/pkg/startrpc/start.go b/pkg/startrpc/start.go index 3eeaaa3a2..18b92573e 100644 --- a/pkg/startrpc/start.go +++ b/pkg/startrpc/start.go @@ -41,6 +41,7 @@ func Start( rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption, ) error { + rpcPort = 10030 fmt.Println( "start", rpcRegisterName,