Documentation ¶
Index ¶
- Constants
- Variables
- func AddValueToCTX(ctx context.Context, key, data string) context.Context
- func GetClientUidByCTX(ctx context.Context) (int32, error)
- func GetDstSvidByCTX(ctx context.Context) (int32, error)
- func GetRemoteIpByCTX(ctx context.Context) (string, error)
- func GetValueFromCTX(ctx context.Context, key string) (string, bool)
- func NewContextWithRemoteIp(ctx context.Context, remoteIp string) context.Context
- func NewContextWithSeq(ctx context.Context, seq int32) context.Context
- func NewContextWithUid(ctx context.Context, uid int64) context.Context
- func XCall(ctx context.Context, serviceName string, funcName string, args TheMarshaler, ...) error
- func XCallBytes(ctx context.Context, serviceName string, funcName string, args interface{}, ...) error
- func XCallBytesWithSvid(ctx context.Context, serviceName string, funcName string, args interface{}, ...) error
- func XCallWithRoutefunc(ctx context.Context, serviceName string, funcName string, args TheMarshaler, ...) error
- func XCallWithSvid(ctx context.Context, serviceName string, funcName string, args TheMarshaler, ...) error
- type Clients
- type MySelector
- type RouteCallback
- type TheMarshaler
Constants ¶
View Source
const ( //rpc透传时,map中的field名称.(放到const中主要是为了避免滥用冲突) ReqMetaDataKey_FIELD_srcName = "srcName" //传递rpc请求源的名称 ReqMetaDataKey_FIELD_srcSvid = "srcSvid" //传递rpc请求源的svrid ReqMetaDataKey_FIELD_clientSeq = "clientSeq" //传递客户端请求序列号,rpc服务在必要时可以快速响应该seq的请求.(比如 game服快速响应操作) ReqMetaDataKey_FIELD_clientUid = "clientUid" //rpc调用时,传递客户端的这个socket连接对应的uid,便于业务做安全性检测 ReqMetaDataKey_FIELD_dstSvid = "dstSvid" //rpcClient中记录下目标svrid,以便于选择合适的服务端 ReqMetaDataKey_FIELD_remoteIp = "remoteIp" //请求方的ip地址;access转入登录的时候会用到。 )
rpc协议中,透传map中的自定义字段名称.
Variables ¶
View Source
var ( MyClients = &Clients{mp: make(map[string]client.XClient), mpcb: make(map[string]RouteCallback)} MyClientsWithBytes = &Clients{mp: make(map[string]client.XClient), mpcb: make(map[string]RouteCallback)} BasePath string FailMode = client.Failfast SelectMode = client.RandomSelect //自定义配置,默认编码方式修改为PB,不使用maspack(因为:使用msgpack的时候,pb中修改了字段的话,用到了该结构体的多出服务都需要重启,否则会报如下错误) //2020/07/16 17:18:50 server.go:414: WARN : rpcx: failed to handle request: RPC获取userInfo出错! LoginService Login NormalOption = client.Option{ Retries: 3, RPCPath: share.DefaultRPCPath, ConnectTimeout: 10 * time.Second, SerializeType: protocol.ProtoBuffer, CompressType: protocol.None, BackupLatency: 10 * time.Millisecond, } //自定义配置,核心:SerializeType,透传的时候使用 MyOptions = client.Option{ Retries: 3, RPCPath: share.DefaultRPCPath, ConnectTimeout: 10 * time.Second, SerializeType: protocol.SerializeNone, CompressType: protocol.None, BackupLatency: 10 * time.Millisecond, } )
Functions ¶
func GetClientUidByCTX ¶
从context中获取本次rpc来源的uid
func GetDstSvidByCTX ¶
获取context透传下来的dstSvid 发起指定了svrid的调用时,会用到该方法。
func GetRemoteIpByCTX ¶
从context中获取本次rpc来源的ip地址
func NewContextWithRemoteIp ¶
把ip地址透传到下一个调用中去。
func NewContextWithSeq ¶
把seq也透传到下一个调用中去。
func NewContextWithUid ¶
把uid也透传到下一个调用中去。
func XCall ¶
func XCall(ctx context.Context, serviceName string, funcName string, args TheMarshaler, reply interface{}) error
封装好发起rpc调用的客户端!
func XCallBytes ¶
func XCallBytes(ctx context.Context, serviceName string, funcName string, args interface{}, reply interface{}, cb RouteCallback) error
封装好发起rpc调用的客户端!(args和reply都是字节切片的格式),以插件的形式实现!
func XCallBytesWithSvid ¶
func XCallBytesWithSvid(ctx context.Context, serviceName string, funcName string, args interface{}, reply interface{}, dstSvid int32) error
封装好发起rpc调用的客户端,且指定目标svrid!(args和reply都是字节切片的格式),以插件的形式实现!
func XCallWithRoutefunc ¶
func XCallWithRoutefunc(ctx context.Context, serviceName string, funcName string, args TheMarshaler, reply interface{}, cb RouteCallback) error
func XCallWithSvid ¶
func XCallWithSvid(ctx context.Context, serviceName string, funcName string, args TheMarshaler, reply interface{}, dstSvid int32) error
根据指定的svid发起rpc调用
Types ¶
type MySelector ¶
type MySelector struct { Dofunc RouteCallback // contains filtered or unexported fields }
func (*MySelector) Select ¶
func (s *MySelector) Select(ctx context.Context, servicePath, serviceMethod string, args interface{}) string
func (*MySelector) UpdateServer ¶
func (s *MySelector) UpdateServer(servers map[string]string)
type RouteCallback ¶
type TheMarshaler ¶
传入的请求参数必须是实现了marshal的接口 修改说明:在改之前调用XCall时的args参数类型是interface{},此处添加TheMarshaler之后,就确保了传入的参数必须是实现了Marshal方法的结构体指针。避免了传入结构体的运行时错误。
Click to show internal directories.
Click to hide internal directories.