Documentation ¶
Overview ¶
Package network provides network related functions.
Index ¶
Constants ¶
View Source
const ( // ConnectionShort 短连接模式 ConnectionShort int = iota // ConnectionLong 长连接模式 ConnectionLong )
Variables ¶
View Source
var ( // DefaultServerServiceToConnectionControl 不同系统服务使用不同的连接持有模式 DefaultServerServiceToConnectionControl = map[config.ClusterType]int{ config.DiscoverCluster: ConnectionLong, config.ConfigCluster: ConnectionShort, config.HealthCheckCluster: ConnectionShort, config.MonitorCluster: ConnectionShort, } )
Functions ¶
func IsAvailableConnection ¶
func IsAvailableConnection(conn *Connection) bool
IsAvailableConnection whether the connection is available
func ToGRPCConn ¶
func ToGRPCConn(conn ClosableConn) *grpc.ClientConn
ToGRPCConn convert to a grpc connection
Types ¶
type ClientInfo ¶
ClientInfo 当前客户端相关信息
type ClosableConn ¶
type ClosableConn interface { // Close 关闭并释放 Close() error }
ClosableConn you can close the connection object
type ConnCreator ¶
type ConnCreator interface { // Name 插件名 Name() string // CreateConnection 创建实际的连接 CreateConnection(address string, timeout time.Duration, clientInfo *ClientInfo) (ClosableConn, error) }
ConnCreator 连接创建器
type ConnID ¶
type ConnID struct { // ID 唯一ID ID uint32 // Service 所属服务 Service config.ClusterService // Address 目标server地址 Address string // contains filtered or unexported fields }
ConnID 连接标识
type Connection ¶
type Connection struct { ConnID // Conn connect the entity of grpc connection Conn ClosableConn // contains filtered or unexported fields }
Connection GRPC connection object containing a unique connection ID
func (*Connection) ForceClose ¶
func (c *Connection) ForceClose() bool
ForceClose forcibly close the connection
func (*Connection) Release ¶
func (c *Connection) Release(opKey string)
Release the connection release
type ConnectionManager ¶
type ConnectionManager interface { // SetConnCreator 设置当前协议的连接创建器 SetConnCreator(creator ConnCreator) // Destroy 销毁并释放连接管理器 Destroy() // GetConnection 获取并占用连接 GetConnection(opKey string, clusterType config.ClusterType) (*Connection, error) // GetConnectionByHashKey 通过传入一致性hashKey的方式获取链接 GetConnectionByHashKey(opKey string, clusterType config.ClusterType, hashKey []byte) (*Connection, error) // ReportConnectionDown 报告连接故障 ReportConnectionDown(connID ConnID) // ReportSuccess 上报接口调用成功 ReportSuccess(connID ConnID, retCode int32, timeout time.Duration) // ReportFail 上报接口调用失败 ReportFail(connID ConnID, retCode int32, timeout time.Duration) // UpdateServers 更新服务地址 UpdateServers(svcEventKey model.ServiceEventKey) // GetClientInfo 获取当前客户端信息 GetClientInfo() *ClientInfo // IsReady discover服务是否已经就绪 IsReady() bool // GetHashExpectedInstance 计算hash Key对应的实例 GetHashExpectedInstance(clusterType config.ClusterType, hash []byte) (string, model.Instance, error) // ConnectByAddr 直接通过addr连接,慎使用 ConnectByAddr(clusterType config.ClusterType, addr string, instance model.Instance) (*Connection, error) }
ConnectionManager 通用的连接管理器
func NewConfigConnectionManager ¶ added in v1.1.0
func NewConfigConnectionManager(cfg config.Configuration, valueCtx model.ValueContext) (ConnectionManager, error)
NewConfigConnectionManager 创建配置中心连接管理器
func NewConnectionManager ¶
func NewConnectionManager( cfg config.Configuration, valueCtx model.ValueContext) (ConnectionManager, error)
NewConnectionManager 创建连接管理器
type ServerAddressList ¶
type ServerAddressList struct {
// contains filtered or unexported fields
}
ServerAddressList 服务地址列表
func (*ServerAddressList) ConnectServerByAddrOnly ¶
func (s *ServerAddressList) ConnectServerByAddrOnly(addr string, timeout time.Duration, clsService config.ClusterService, instance model.Instance) (*Connection, error)
ConnectServerByAddrOnly 。根据地址进行链接
Click to show internal directories.
Click to hide internal directories.