-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xinwei Xiong (cubxxw) <[email protected]>
- Loading branch information
Showing
5 changed files
with
170 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,22 @@ | ||
package discoveryregister | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/OpenIMSDK/tools/discoveryregistry" | ||
openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper" | ||
"github.com/OpenIMSDK/tools/log" | ||
"google.golang.org/grpc" | ||
"github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/kubernetes" | ||
"github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/zookeeper" | ||
|
||
"github.com/openimsdk/open-im-server/v3/pkg/common/config" | ||
"github.com/OpenIMSDK/tools/discoveryregistry" | ||
) | ||
|
||
// NewDiscoveryRegister creates a new service discovery and registry client based on the provided environment type. | ||
func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistry, error) { | ||
var client discoveryregistry.SvcDiscoveryRegistry | ||
var err error | ||
switch envType { | ||
case "zookeeper": | ||
client, err = openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, | ||
openkeeper.WithFreq(time.Hour), openkeeper.WithUserNameAndPassword( | ||
config.Config.Zookeeper.Username, | ||
config.Config.Zookeeper.Password, | ||
), openkeeper.WithRoundRobin(), openkeeper.WithTimeout(10), openkeeper.WithLogger(log.NewZkLogger())) | ||
return zookeeper.NewZookeeperDiscoveryRegister() | ||
case "k8s": | ||
client, err = NewK8sDiscoveryRegister() | ||
return kubernetes.NewK8sDiscoveryRegister() | ||
default: | ||
client = nil | ||
err = errors.New("envType not correct") | ||
return nil, errors.New("envType not correct") | ||
} | ||
return client, err | ||
} | ||
|
||
type K8sDR struct { | ||
options []grpc.DialOption | ||
rpcRegisterAddr string | ||
} | ||
|
||
func NewK8sDiscoveryRegister() (discoveryregistry.SvcDiscoveryRegistry, error) { | ||
return &K8sDR{}, nil | ||
} | ||
|
||
func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.DialOption) error { | ||
cli.rpcRegisterAddr = serviceName | ||
return nil | ||
} | ||
func (cli *K8sDR) UnRegister() error { | ||
|
||
return nil | ||
} | ||
func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error { | ||
|
||
return nil | ||
} | ||
func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error { | ||
|
||
return nil | ||
} | ||
|
||
func (cli *K8sDR) GetConfFromRegistry(key string) ([]byte, error) { | ||
|
||
return nil, nil | ||
} | ||
func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) { | ||
|
||
conn, err := grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...) | ||
return []*grpc.ClientConn{conn}, err | ||
} | ||
func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { | ||
|
||
return grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...) | ||
} | ||
func (cli *K8sDR) GetSelfConnTarget() string { | ||
|
||
return cli.rpcRegisterAddr | ||
} | ||
func (cli *K8sDR) AddOption(opts ...grpc.DialOption) { | ||
cli.options = append(cli.options, opts...) | ||
} | ||
func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) { | ||
conn.Close() | ||
} | ||
|
||
// do not use this method for call rpc | ||
func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn { | ||
fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!") | ||
return nil | ||
} | ||
func (cli *K8sDR) Close() { | ||
return | ||
} |
Oops, something went wrong.