Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create RPC zookeeper node to prevent interface call blocking. #496

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/openimsdk/chat

go 1.21.2
go 1.20

require (
github.com/gin-gonic/gin v1.9.1
Expand All @@ -27,7 +27,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/gomake v0.0.6
github.com/openimsdk/protocol v0.0.63
github.com/openimsdk/tools v0.0.47-alpha.43
github.com/openimsdk/tools v0.0.48
github.com/redis/go-redis/v9 v9.5.1
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand Down
55 changes: 2 additions & 53 deletions go.sum

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions internal/api/admin/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func Start(ctx context.Context, index int, config *Config) error {
if err != nil {
return err
}

if err = client.CreateRpcRootNodes(config.Share.RpcRegisterName.GetServiceNames()); err != nil {
return errs.WrapMsg(err, "failed to create RPC root nodes")
}

chatConn, err := client.GetConn(ctx, config.Share.RpcRegisterName.Chat, grpc.WithTransportCredentials(insecure.NewCredentials()), mw.GrpcClient())
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions internal/api/chat/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func Start(ctx context.Context, index int, config *Config) error {
if err != nil {
return err
}

if err = client.CreateRpcRootNodes(config.Share.RpcRegisterName.GetServiceNames()); err != nil {
return errs.WrapMsg(err, "failed to create RPC root nodes")
}
chatConn, err := client.GetConn(ctx, config.Share.RpcRegisterName.Chat, grpc.WithTransportCredentials(insecure.NewCredentials()), mw.GrpcClient())
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/cmd/admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewAdminApiCmd() *AdminApiCmd {
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
return ret.preRunE()
return ret.runE()
}
return &ret
}
Expand All @@ -34,6 +34,6 @@ func (a *AdminApiCmd) Exec() error {
return a.Execute()
}

func (a *AdminApiCmd) preRunE() error {
func (a *AdminApiCmd) runE() error {
return admin.Start(a.ctx, a.Index(), &a.apiConfig)
}
4 changes: 2 additions & 2 deletions pkg/common/cmd/admin_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewAdminRpcCmd() *AdminRpcCmd {
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
return ret.preRunE()
return ret.runE()
}
return &ret
}
Expand All @@ -51,7 +51,7 @@ func (a *AdminRpcCmd) Exec() error {
return a.Execute()
}

func (a *AdminRpcCmd) preRunE() error {
func (a *AdminRpcCmd) runE() error {
return startrpc.Start(a.ctx, &a.adminConfig.ZookeeperConfig, a.adminConfig.RpcConfig.RPC.ListenIP,
a.adminConfig.RpcConfig.RPC.RegisterIP, a.adminConfig.RpcConfig.RPC.Ports,
a.Index(), a.adminConfig.Share.RpcRegisterName.Admin, &a.adminConfig.Share, &a.adminConfig, admin.Start)
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/cmd/chat_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewChatApiCmd() *ChatApiCmd {
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
return ret.preRunE()
return ret.runE()
}
return &ret
}
Expand All @@ -34,6 +34,6 @@ func (a *ChatApiCmd) Exec() error {
return a.Execute()
}

func (a *ChatApiCmd) preRunE() error {
func (a *ChatApiCmd) runE() error {
return chat.Start(a.ctx, a.Index(), &a.apiConfig)
}
4 changes: 2 additions & 2 deletions pkg/common/cmd/chat_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewChatRpcCmd() *ChatRpcCmd {
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
return ret.preRunE()
return ret.runE()
}
return &ret
}
Expand All @@ -51,7 +51,7 @@ func (a *ChatRpcCmd) Exec() error {
return a.Execute()
}

func (a *ChatRpcCmd) preRunE() error {
func (a *ChatRpcCmd) runE() error {
return startrpc.Start(a.ctx, &a.chatConfig.ZookeeperConfig, a.chatConfig.RpcConfig.RPC.ListenIP,
a.chatConfig.RpcConfig.RPC.RegisterIP, a.chatConfig.RpcConfig.RPC.Ports,
a.Index(), a.chatConfig.Share.RpcRegisterName.Chat, &a.chatConfig.Share, &a.chatConfig, chat.Start)
Expand Down
7 changes: 7 additions & 0 deletions pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type RpcRegisterName struct {
Admin string `mapstructure:"admin"`
}

func (r *RpcRegisterName) GetServiceNames() []string {
return []string{
r.Chat,
r.Admin,
}
}

type API struct {
Api struct {
ListenIP string `mapstructure:"listenIP"`
Expand Down
Loading