service_router

package module
v0.0.0-...-a29460c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2022 License: Apache-2.0 Imports: 27 Imported by: 4

Documentation

Index

Constants

View Source
const (
	PREFIX                                           = "ads_core_go"
	NAMESPACE                                        = "service_router"
	ROUTER_VERSION                                   = "service_router_version"
	ROUTER_MAJOR_VERSION                             = "major_version"
	ROUTER_MINOR_VERSION                             = "minor_version"
	ROUTER_REVISION                                  = "revision"
	ROUTER_METRICS_SELECT_ADDRESS                    = "select_address"
	ROUTER_METRICS_SELECT_ADDRESS_TAGS_ADDR          = "addr"
	ROUTER_METRICS_SELECT_ADDRESS_TAGS_ADDR_VAL_NONE = "none"
	POOL_METRICS_AQUIRE_BLOCKED                      = "pool_aquire_blocked"
	POOL_IDLE_CONNECTIONS                            = "pool_idle_connections"
	POOL_ACTIVE_CONNECTIONS                          = "pool_active_connections"
	METRICS_URI                                      = "/ads-core/metrics"
	PROMETHEUS_URI                                   = "/ads-core/metrics/prometheus"
	RESTART_TIMER                                    = "/ads-core/timer/restart"
	HTTP_SERVER_SUBSCRIBED                           = "/ads-core/router/subscribed"
	HTTP_SERVER_ROUTER_STATIC_SWITCH                 = "/ads-core/router/static_switch"
	HTTP_SERVER_ROUTER_PUT_NODES                     = "/ads-core/router/put_nodes"
)
View Source
const (
	CONSUL_REGISTRY_KV_PREFIX         string = "ads-core/services/"
	CONSUL_REGISTRY_KV_NODES          string = "/nodes/"
	CONSUL_REGISTRY_KV_CONFIG         string = "/config/"
	CONSUL_REGISTRY_KV_CONFIG_ROUTER  string = "router"
	CONSUL_REGISTRY_KV_CONFIG_CONFIGS string = "configs/"
	CONSUL_REGISTRY_KV_CONFIG_VERSION string = "version"
	CONSUL_REGISTRY_KV_KEY_SPLIT      string = ":"
)
View Source
const (
	ServerProtocol_HTTP   = "http"
	ServerProtocol_THRIFT = "thrift"
	ServerProtocol_REDIS  = "redis"
)

服务协议

View Source
const (
	ServerStatus_AVAILABLE   = "available"
	ServerStatus_UNAVAILABLE = "unavailable"
	ServerStatus_UNKNOWN     = "unknown"
)

服务状态

View Source
const (
	LoadBalanceMethod_RANDOM              = "random"
	LoadBalanceMethod_ROUNDROBIN          = "roundrobin"
	LoadBalanceMethod_LOCALFIRST          = "localfirst"
	LoadBalanceMethod_CONSISTENT          = "consistent"
	LoadBalanceMethod_CONFIGURABLE_WEIGHT = "configurable_weight"
	LoadBalanceMethod_ACTIVE_WEIGHT       = "active_weight"
	LoadBalanceMethod_USER_DEFINED        = "user_defined"
	LoadBalanceMethod_IPRANGEFIRST        = "iprangefirst"
	LoadBalanceMethod_STATIC_WEIGHT       = "static_weight"
)
View Source
const (
	ShardType_ALL      = "0"
	ShardType_LEADER   = "1"
	ShardType_FOLLOWER = "2"
)
View Source
const (
	ServicePullerType_Config = "CONFIG_PULLER"
	ServicePullerType_Server = "SERVER_PULLER"
)
View Source
const (
	DEFAULT_DC = "default"
)
View Source
const UINT32MAX int64 = 4294967295 // 2^32 - 1

Variables

View Source
var (
	ErrInvalidServer = errors.New("invalid server")
)
View Source
var (
	ErrPoolExhausted = errors.New("connection pool exhausted")
)

Functions

func Gcd

func Gcd(a uint32, b uint32) uint32

最大公约数

func GetConfigPath

func GetConfigPath(server *Server) string

func GetConfigVersionPath

func GetConfigVersionPath(server *Server) string

func GetConfigsPath

func GetConfigsPath(server *Server) string

func GetNodeName

func GetNodeName(server *Server) string

func GetNodePath

func GetNodePath(server *Server) string

func GetNodesPath

func GetNodesPath(server *Server) string

func GetRouterConfigPath

func GetRouterConfigPath(server *Server) string

func GetServiceKey

func GetServiceKey(serviceName string, protocol string, routerId int64, shardType string, dc string) int64

func GetServices

func GetServices(server *Server) string

func IpToInt

func IpToInt(ip string) uint32

Types

type Action

type Action func(conn interface{}) (interface{}, error)

type BalanceLocalFirstConfig

type BalanceLocalFirstConfig struct {
	LocalIp   string
	DiffRange int
}

func DefaultBalanceLocalFirstConfig

func DefaultBalanceLocalFirstConfig() BalanceLocalFirstConfig

Get default BalanceLocalFirstConfig

type ClientOption

type ClientOption struct {
	ServiceName         string
	ShardId             int64
	ShardType           string
	Protocol            string
	Loadbalance         string
	TargetServerAddress ServerAddress
	UserBalance         LoadBalance
	LocalFirstConfig    BalanceLocalFirstConfig
	PartitionHash       int64
	RouteToEdgeNode     bool
	Idc                 string
	Dc                  string
}

func ClientOptionFactory

func ClientOptionFactory(serviceName string, protocol string) ClientOption

func DefaultClientOption

func DefaultClientOption() ClientOption

Get Default ClientOption

type CloseThriftClient

type CloseThriftClient func(client ThriftClient) error

type ConfigSubscriber

type ConfigSubscriber interface {
	ConfigNotify(serviceName string, serviceConfig ServiceConfig)
}

ConfigSubscriber interface

type Conn

type Conn interface {
	io.Closer
	Err() error            // 获取错误信息
	Good(t time.Time) bool // 在获取连接的时候调用
	SetErr(err error)      // 在出现错误的时候调用
	ForceClose() bool      // 在释放连接前调用
	Do(action Action) *Done
}

type ConnGroup

type ConnGroup struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func GetConnGroup

func GetConnGroup() *ConnGroup

func (*ConnGroup) GetConnection

func (cg *ConnGroup) GetConnection(
	config ThriftConfig,
	opts ...PoolOption,
) (Conn, error)

type ConsulRegistry

type ConsulRegistry struct {
	// contains filtered or unexported fields
}

ConsulRegistry class

func NewConsulRegistry

func NewConsulRegistry(config *api.Config) (*ConsulRegistry, error)

Constructor

func (*ConsulRegistry) Available

func (cr *ConsulRegistry) Available(server Server) error

func (*ConsulRegistry) DisableStatic

func (cr *ConsulRegistry) DisableStatic(serviceName string) error

func (*ConsulRegistry) Discover

func (cr *ConsulRegistry) Discover(serviceName string)

ConsulRegistry::discover

func (*ConsulRegistry) EnableStatic

func (cr *ConsulRegistry) EnableStatic(serviceName string) error

func (*ConsulRegistry) GetAllSubscribed

func (cr *ConsulRegistry) GetAllSubscribed() []string

func (*ConsulRegistry) GetConfig

func (cr *ConsulRegistry) GetConfig(serviceName string)

ConsulRegistry::getConfig

func (*ConsulRegistry) GetValue

func (cr *ConsulRegistry) GetValue(key string) (string, bool)

func (*ConsulRegistry) PushStaticNodes

func (cr *ConsulRegistry) PushStaticNodes(serviceName string, serverList ServerList) error

func (*ConsulRegistry) PutRouterConfig

func (cr *ConsulRegistry) PutRouterConfig(server Server, config ServiceRouterConfig) error

func (*ConsulRegistry) PutServiceConfigs

func (cr *ConsulRegistry) PutServiceConfigs(server Server, configs map[string]string) error

func (*ConsulRegistry) RegisterServer

func (cr *ConsulRegistry) RegisterServer(server Server) error

func (*ConsulRegistry) SubscribeConfig

func (cr *ConsulRegistry) SubscribeConfig(serviceName string, subscriber ConfigSubscriber)

subscribe config

func (*ConsulRegistry) SubscribeService

func (cr *ConsulRegistry) SubscribeService(serviceName string, subscriber ServiceSubscriber)

subscribe service

func (*ConsulRegistry) Unavailable

func (cr *ConsulRegistry) Unavailable(server Server) error

func (*ConsulRegistry) UnregisterConfig

func (cr *ConsulRegistry) UnregisterConfig(server Server) error

func (*ConsulRegistry) UnregisterServer

func (cr *ConsulRegistry) UnregisterServer(server Server) error

func (*ConsulRegistry) UnsubscribeConfig

func (cr *ConsulRegistry) UnsubscribeConfig(serviceName string)

func (*ConsulRegistry) UnsubscribeService

func (cr *ConsulRegistry) UnsubscribeService(serviceName string)

type ConsulServiceConfigPull

type ConsulServiceConfigPull struct {
	// contains filtered or unexported fields
}

func GetConsulServiceConfigPull

func GetConsulServiceConfigPull(registry Registry) *ConsulServiceConfigPull

func (*ConsulServiceConfigPull) Pull

func (scp *ConsulServiceConfigPull) Pull(serviceName string)

type ConsulServiceInfoPull

type ConsulServiceInfoPull struct {
	// contains filtered or unexported fields
}

func GetConsulServiceInfoPull

func GetConsulServiceInfoPull(registry Registry) *ConsulServiceInfoPull

singleton

func (*ConsulServiceInfoPull) Pull

func (sip *ConsulServiceInfoPull) Pull(serviceName string)

type ConsulServicePush

type ConsulServicePush struct {
	// contains filtered or unexported fields
}

func NewConsulServicePush

func NewConsulServicePush(registry Registry) *ConsulServicePush

func (*ConsulServicePush) Push

func (csp *ConsulServicePush) Push(server Server) error

type CurrentStateWrapper

type CurrentStateWrapper struct {
	// contains filtered or unexported fields
}

type Done

type Done struct {
	Then *Then
}

func (*Done) Done

func (d *Done) Done(done DoneFunc) *Then

type DoneFunc

type DoneFunc func()

type LoadBalance

type LoadBalance interface {
	Select(serverList ServerList) (*Server, bool)
}

LoadBalance interface

type LoadBalanceConfigurableWeight

type LoadBalanceConfigurableWeight struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LoadBalanceConfigurableWeight

func NewLoadBalanceConfigurableWeight

func NewLoadBalanceConfigurableWeight() *LoadBalanceConfigurableWeight

func (*LoadBalanceConfigurableWeight) Select

func (bcw *LoadBalanceConfigurableWeight) Select(serverList ServerList) (*Server, bool)

type LoadBalanceIpRangeFirst

type LoadBalanceIpRangeFirst struct {
	// contains filtered or unexported fields
}

LoadBalanceIpRangeFirst

func NewLoadBalanceIpRangeFirst

func NewLoadBalanceIpRangeFirst(config BalanceLocalFirstConfig) *LoadBalanceIpRangeFirst

func (*LoadBalanceIpRangeFirst) Select

func (lbirf *LoadBalanceIpRangeFirst) Select(serverList ServerList) (*Server, bool)

type LoadBalanceLocalFirst

type LoadBalanceLocalFirst struct {
	// contains filtered or unexported fields
}

LoadBalanceLocalFirst

func NewLoadBalanceLocalFirst

func NewLoadBalanceLocalFirst(config BalanceLocalFirstConfig) *LoadBalanceLocalFirst

func (*LoadBalanceLocalFirst) Select

func (lblf *LoadBalanceLocalFirst) Select(serverList ServerList) (*Server, bool)

type LoadBalanceRandom

type LoadBalanceRandom struct {
}

LoadBalanceRandom

func NewLoadBalanceRandom

func NewLoadBalanceRandom() *LoadBalanceRandom

func (*LoadBalanceRandom) Select

func (lbr *LoadBalanceRandom) Select(serverList ServerList) (*Server, bool)

type LoadBalanceRoundrobin

type LoadBalanceRoundrobin struct {
	// contains filtered or unexported fields
}

LoadBalanceRoundrobin

func NewLoadBalanceRoundrobin

func NewLoadBalanceRoundrobin() *LoadBalanceRoundrobin

func (*LoadBalanceRoundrobin) Select

func (lbrr *LoadBalanceRoundrobin) Select(serverList ServerList) (*Server, bool)

type LoadBalanceStaticWeight

type LoadBalanceStaticWeight struct {
}

LoadBalanceStaticWeight

func NewLoadBalanceStaticWeight

func NewLoadBalanceStaticWeight() *LoadBalanceStaticWeight

func (*LoadBalanceStaticWeight) Select

func (lbsw *LoadBalanceStaticWeight) Select(serverList ServerList) (*Server, bool)

type Multiplexer

type Multiplexer func(string, http.Handler)

type OnError

type OnError func(err error)

type OnSuccess

type OnSuccess func(resp interface{})

type Pool

type Pool struct {
	sync.Mutex
	Factory     func() (Conn, error)
	MaxIdle     int // Maximum number of idle connections in the pool
	MaxActive   int // Maximum number of connections allocated by the pool, MaxActive >= MaxIdle
	IdleTimeout time.Duration
	Wait        bool
	Metric      tally.Scope
	// contains filtered or unexported fields
}

func NewPool

func NewPool(factory func() (Conn, error), opt ...PoolOption) *Pool

func (*Pool) Aquire

func (p *Pool) Aquire() (Conn, error)

func (*Pool) Close

func (p *Pool) Close() error

type PoolOption

type PoolOption func(*poolOptions)

func PoolIdleTimeout

func PoolIdleTimeout(t time.Duration) PoolOption

func PoolMaxActive

func PoolMaxActive(n int) PoolOption

func PoolMaxIdle

func PoolMaxIdle(n int) PoolOption

func PoolMetric

func PoolMetric(m tally.Scope) PoolOption

func PoolWait

func PoolWait(b bool) PoolOption

type Registry

type Registry interface {
	SubscribeService(serviceName string, subscriber ServiceSubscriber)
	UnsubscribeService(serviceName string)
	SubscribeConfig(serviceName string, subscriber ConfigSubscriber)
	UnsubscribeConfig(serviceName string)
	Discover(serviceName string)
	GetConfig(serviceName string)
	GetValue(key string) (string, bool)
	PutRouterConfig(server Server, config ServiceRouterConfig) error
	PutServiceConfigs(server Server, config map[string]string) error
	RegisterServer(server Server) error
	UnregisterServer(server Server) error
	UnregisterConfig(server Server) error
	Available(server Server) error
	Unavailable(server Server) error
	GetAllSubscribed() []string
	PushStaticNodes(serviceName string, serverList ServerList) error
	EnableStatic(serviceName string) error
	DisableStatic(serviceName string) error
}

type Router

type Router struct {
	// contains filtered or unexported fields
}

func GetRouter

func GetRouter(config *RouterConfig) *Router

singleton

func (*Router) BatchDiscover

func (router *Router) BatchDiscover(option ClientOption, routerIds []int64) map[int64]*Server

通过shardIds批量发现

func (*Router) ConfigNotify

func (router *Router) ConfigNotify(serviceName string, serviceConfig ServiceConfig)

update timer

func (*Router) Discover

func (router *Router) Discover(option ClientOption) (*Server, bool)

func (*Router) GetAllSubscribed

func (router *Router) GetAllSubscribed() http.Handler

func (*Router) GetConfigs

func (router *Router) GetConfigs(name string) (map[string]string, bool)

func (*Router) GetCounter

func (router *Router) GetCounter(server *Server) tally.Counter

func (*Router) GetMetrics

func (router *Router) GetMetrics() tally.Scope

func (*Router) GetOrCreateBalancer

func (router *Router) GetOrCreateBalancer(option ClientOption) LoadBalance

func (*Router) GetOrCreateConfigPuller

func (router *Router) GetOrCreateConfigPuller(serviceName string) *ServicePuller

func (*Router) GetOrCreateDiscoverPuller

func (router *Router) GetOrCreateDiscoverPuller(serviceName string) *ServicePuller

func (*Router) GetOrCreateServicePusher

func (router *Router) GetOrCreateServicePusher(server Server) *ServicePusher

func (*Router) GetRegistry

func (router *Router) GetRegistry() Registry

func (*Router) GetRouterDb

func (router *Router) GetRouterDb() RouterDb

func (*Router) GetServerList

func (router *Router) GetServerList(option ClientOption) (ServerList, bool)

func (*Router) GetServiceRouterConfig

func (router *Router) GetServiceRouterConfig(serviceName string) (*ServiceRouterConfig, bool)

func (*Router) PushStaticNodes

func (router *Router) PushStaticNodes() http.Handler

func (*Router) RegisterServer

func (router *Router) RegisterServer(server Server)

func (*Router) RestartTimerHandler

func (router *Router) RestartTimerHandler() http.Handler

func (*Router) SetRouterDb

func (router *Router) SetRouterDb(db RouterDb)

func (*Router) StaticSwitch

func (router *Router) StaticSwitch() http.Handler

type RouterConfig

type RouterConfig struct {
	Consul      api.Config
	ProjectName string
	LocalIp     string
	HttpPort    int
	Multiplexer Multiplexer
}

type RouterDb

type RouterDb interface {
	ServiceSubscriber
	ConfigSubscriber

	GetConfigs() map[string]ServiceConfig
	GetServiceConfig(serviceName string) (map[string]string, bool)
	GetServiceRouterConfig(serviceName string) ServiceRouterConfig
	PickServers(serviceName string, serviceList ServerList) ServerList
	UpdateServers(serviceName string, serverList ServerList)
	UpdateConfig(serviceName string, config ServiceConfig)
	SelectServers(serviceName string, protocol string, routerId int64, shardType string, dc string) (ServerList, bool)
	BatchSelectServers(serviceName, protocol string, routerIds []int64, shardType string, dc string) map[int64]ServerList
}

func GetRouterDb

func GetRouterDb() RouterDb

type RouterDbImpl

type RouterDbImpl struct {
	// contains filtered or unexported fields
}

RouterDbImpl所提供的api返回的数据必须是副本 golang没法控制引用的写权限

func (*RouterDbImpl) BatchSelectServers

func (rd *RouterDbImpl) BatchSelectServers(serviceName, protocol string, routerIds []int64, shardType string, dc string) map[int64]ServerList

func (*RouterDbImpl) ConfigNotify

func (rd *RouterDbImpl) ConfigNotify(serviceName string, serviceConfig ServiceConfig)

func (*RouterDbImpl) GetConfigs

func (rd *RouterDbImpl) GetConfigs() map[string]ServiceConfig

func (*RouterDbImpl) GetServiceConfig

func (rd *RouterDbImpl) GetServiceConfig(serviceName string) (map[string]string, bool)

func (*RouterDbImpl) GetServiceRouterConfig

func (rd *RouterDbImpl) GetServiceRouterConfig(serviceName string) ServiceRouterConfig

func (*RouterDbImpl) PickServers

func (rd *RouterDbImpl) PickServers(serviceName string, serviceList ServerList) ServerList

func (*RouterDbImpl) SelectServers

func (rd *RouterDbImpl) SelectServers(serviceName string, protocol string, routerId int64, shardType string, dc string) (ServerList, bool)

func (*RouterDbImpl) ServiceNotify

func (rd *RouterDbImpl) ServiceNotify(serviceName string, services ServerList)

func (*RouterDbImpl) UpdateConfig

func (rd *RouterDbImpl) UpdateConfig(serviceName string, config ServiceConfig)

func (*RouterDbImpl) UpdateServers

func (rd *RouterDbImpl) UpdateServers(serviceName string, serverList ServerList)

type Server

type Server struct {
	Host                       string            `json:"Host"`
	Port                       uint16            `json:"Port"`
	ServiceName                string            `json:"ServiceName"`
	Protocol                   string            `json:"Protocol"`
	Status                     string            `json:"Status"`
	UpdateTime                 uint64            `json:"UpdateTime"`
	Weight                     uint32            `json:"Weight"`
	ShardList                  []uint32          `json:"ShardList"`
	AvailableShardList         []uint32          `json:"AvailableShardList"`
	FollowerShardList          []uint32          `json:"FollowerShardList"`
	FollowerAvailableShardList []uint32          `json:"FollowerAvailableShardList"`
	OtherSettings              map[string]string `json:"OtherSettings"`
	PartitionList              []int64           `json:"PartitionList"`
	IsEdgeNode                 bool              `json:"IsEdgeNode"`
	Idc                        string            `json:"Idc"`
	Dc                         string            `json:"Dc"`
}

服务

type ServerAddress

type ServerAddress struct {
	Host string `json:"Host" toml:"Host"`
	Port uint16 `json:"Port" toml:"Port"`
}

type ServerList

type ServerList []Server

type ServiceConfig

type ServiceConfig struct {
	Router  ServiceRouterConfig
	Configs map[string]string
}

type ServicePull

type ServicePull interface {
	Pull(serviceName string)
}

service pull interface

type ServicePuller

type ServicePuller struct {
	// contains filtered or unexported fields
}

func NewServicePuller

func NewServicePuller(serviceName string, servicePull ServicePull, routerConfig ServiceRouterConfig, pullerType string) *ServicePuller

func (*ServicePuller) Reload

func (sp *ServicePuller) Reload(interval time.Duration)

func (*ServicePuller) Restart

func (sp *ServicePuller) Restart()

func (*ServicePuller) Start

func (sp *ServicePuller) Start(ctx context.Context)

func (*ServicePuller) Stop

func (sp *ServicePuller) Stop()

type ServicePush

type ServicePush interface {
	Push(server Server) error
}

type ServicePusher

type ServicePusher struct {
	// contains filtered or unexported fields
}

func NewServicePusher

func NewServicePusher(server Server, push ServicePush, routerConfig ServiceRouterConfig) *ServicePusher

func (*ServicePusher) Reload

func (sh *ServicePusher) Reload(ttl time.Duration)

func (*ServicePusher) Restart

func (sh *ServicePusher) Restart()

func (*ServicePusher) SetAvailableShardList

func (sh *ServicePusher) SetAvailableShardList(shardList []uint32)

func (*ServicePusher) SetFollowerAvailableShardList

func (sh *ServicePusher) SetFollowerAvailableShardList(shardList []uint32)

func (*ServicePusher) SetFollowerShardList

func (sh *ServicePusher) SetFollowerShardList(shardList []uint32)

func (*ServicePusher) SetIsEdgeNode

func (sh *ServicePusher) SetIsEdgeNode(isEdgeNode bool)

func (*ServicePusher) SetPartitionList

func (sh *ServicePusher) SetPartitionList(partition_list []int64)

func (*ServicePusher) SetShardList

func (sh *ServicePusher) SetShardList(shardList []uint32)

func (*ServicePusher) SetStatus

func (sh *ServicePusher) SetStatus(status string)

func (*ServicePusher) SetWeight

func (sh *ServicePusher) SetWeight(weight uint32)

func (*ServicePusher) Start

func (sh *ServicePusher) Start(ctx context.Context)

func (*ServicePusher) Stop

func (sh *ServicePusher) Stop()

type ServiceRouterConfig

type ServiceRouterConfig struct {
	TtlInMs           uint32 `json:"TtlInMs" toml:"TtlInMs"`
	LoadBalanceMethod string `json:"LoadBalance" toml:"LoadBalance"`
	TotalShards       uint32 `json:"TotalShards" toml:"TotalShards"`
	PullInterval      uint32 `json:"PullInterval" toml:"PullInterval"`
}

func DefaultServiceRouterConfig

func DefaultServiceRouterConfig() ServiceRouterConfig

Get default ServiceRouterConfig

type ServiceSubscriber

type ServiceSubscriber interface {
	ServiceNotify(serviceName string, services ServerList)
}

ServiceSubscriber interface

type Then

type Then struct {
	Resp interface{}
	Err  error
}

func (*Then) OnError

func (t *Then) OnError(err OnError) *Then

func (*Then) OnSuccess

func (t *Then) OnSuccess(suc OnSuccess) *Then

func (*Then) TryResponse

func (t *Then) TryResponse(suc OnSuccess, err OnError)

type ThriftClient

type ThriftClient interface{}

type ThriftCompressionMethod

type ThriftCompressionMethod uint32
const (
	ThriftCompressionMethod_None   ThriftCompressionMethod = 0
	ThriftCompressionMethod_Zlib   ThriftCompressionMethod = 1
	ThriftCompressionMethod_HMAC   ThriftCompressionMethod = 2
	ThriftCompressionMethod_Snappy ThriftCompressionMethod = 3
	ThriftCompressionMethod_QLZ    ThriftCompressionMethod = 3
	ThriftCompressionMethod_Zstd   ThriftCompressionMethod = 3
)

type ThriftConfig

type ThriftConfig struct {
	Host              string
	Port              int
	TransportType     ThriftTransportType
	CompressionMethod ThriftCompressionMethod
	Timeout           time.Duration
	NewThriftClient   NewThriftClient
	CloseThriftClient CloseThriftClient
	ThriftIsOpen      ThriftIsOpen
}

type ThriftConn

type ThriftConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

unthreadsafe 连接池不会把同一个连接同时分配给两个协程, 但是,在获取连接后,不要并发操作连接

func NewThriftConn

func NewThriftConn(config ThriftConfig) (*ThriftConn, error)

func (*ThriftConn) Close

func (tc *ThriftConn) Close() error

func (*ThriftConn) Do

func (tc *ThriftConn) Do(action Action) *Done

func (*ThriftConn) Err

func (tc *ThriftConn) Err() error

func (*ThriftConn) ForceClose

func (tc *ThriftConn) ForceClose() bool

func (*ThriftConn) Good

func (tc *ThriftConn) Good(_ time.Time) bool

func (*ThriftConn) SetErr

func (tc *ThriftConn) SetErr(err error)

type ThriftIsOpen

type ThriftIsOpen func(client ThriftClient) bool

type ThriftTransportType

type ThriftTransportType string
const (
	THRIFT_TRANSPORT_HEADER  ThriftTransportType = "HEADER"
	THRIFT_TRANSPORT_FREMED  ThriftTransportType = "FRAMED"
	THRIFT_TRANSPORT_HTTP2   ThriftTransportType = "HTTP2"   // not implemented
	THRIFT_TRANSPORT_RSOCKET ThriftTransportType = "RSOCKET" // not implemented
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL