Documentation ¶
Overview ¶
Package module 模块定义
Index ¶
- type App
- type ClientRPCHandler
- type FileNameHandler
- type Module
- type Option
- func BILogDir(v string) Option
- func Configure(v string) Option
- func Debug(t bool) Option
- func KillWaitTTL(t time.Duration) Option
- func LogDir(v string) Option
- func Nats(nc *nats.Conn) Option
- func Parse(t bool) Option
- func ProcessID(v string) Option
- func RPCExpired(t time.Duration) Option
- func RPCMaxCoroutine(t int) Option
- func RegisterInterval(t time.Duration) Option
- func RegisterTTL(t time.Duration) Option
- func Registry(r registry.Registry) Option
- func Selector(r selector.Selector) Option
- func SetClientRPChandler(t ClientRPCHandler) Option
- func SetRpcCompleteHandler(t RpcCompleteHandler) Option
- func SetServerRPCHandler(t ServerRPCHandler) Option
- func Version(v string) Option
- func WithBIFile(name FileNameHandler) Option
- func WithLogFile(name FileNameHandler) Option
- func WorkDir(v string) Option
- type Options
- type ProtocolMarshal
- type RPCModule
- type RPCSerialize
- type RpcCompleteHandler
- type ServerRPCHandler
- type ServerSession
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface { UpdateOptions(opts ...Option) error Run(mods ...Module) error SetMapRoute(fn func(app App, route string) string) error Configure(settings conf.Config) error OnInit(settings conf.Config) error OnDestroy() error Options() Options Transport() *nats.Conn Registry() registry.Registry // Deprecated: 因为命名规范问题函数将废弃,请用GetServerByID代替 GetServerById(id string) (ServerSession, error) GetServerByID(id string) (ServerSession, error) /** filter 调用者服务类型 moduleType|moduleType@moduleID Type 想要调用的服务类型 */ GetRouteServer(filter string, opts ...selector.SelectOption) (ServerSession, error) //获取经过筛选过的服务 GetServersByType(Type string) []ServerSession GetSettings() conf.Config //获取配置信息 // Deprecated: 因为命名规范问题函数将废弃,请用Invoke代替 RpcInvoke(module RPCModule, moduleType string, _func string, params ...interface{}) (interface{}, string) // Deprecated: 因为命名规范问题函数将废弃,请用InvokeNR代替 RpcInvokeNR(module RPCModule, moduleType string, _func string, params ...interface{}) error // Deprecated: 因为命名规范问题函数将废弃,请用Call代替 RpcCall(ctx context.Context, moduleType, _func string, param mqrpc.ParamOption, opts ...selector.SelectOption) (interface{}, string) Invoke(module RPCModule, moduleType string, _func string, params ...interface{}) (interface{}, string) InvokeNR(module RPCModule, moduleType string, _func string, params ...interface{}) error Call(ctx context.Context, moduleType, _func string, param mqrpc.ParamOption, opts ...selector.SelectOption) (interface{}, string) /** 添加一个 自定义参数序列化接口 gate,system 关键词一被占用请使用其他名称 */ AddRPCSerialize(name string, Interface RPCSerialize) error GetRPCSerialize() map[string]RPCSerialize GetModuleInited() func(app App, module Module) OnConfigurationLoaded(func(app App)) error OnModuleInited(func(app App, module Module)) error OnStartup(func(app App)) error SetProtocolMarshal(protocolMarshal func(Trace string, Result interface{}, Error string) (ProtocolMarshal, string)) error /** 与客户端通信的协议包接口 */ ProtocolMarshal(Trace string, Result interface{}, Error string) (ProtocolMarshal, string) NewProtocolMarshal(data []byte) ProtocolMarshal GetProcessID() string WorkDir() string }
App mqant应用定义
type ClientRPCHandler ¶ added in v1.1.14
type ClientRPCHandler func(app App, server registry.Node, rpcinfo *rpcpb.RPCInfo, result interface{}, err string, exec_time int64)
ClientRPCHandler 调用方RPC监控
type FileNameHandler ¶ added in v1.4.13
type Module ¶
type Module interface { Version() string //模块版本 GetType() string //模块类型 OnAppConfigurationLoaded(app App) //当App初始化时调用,这个接口不管这个模块是否在这个进程运行都会调用 OnConfChanged(settings *conf.ModuleSettings) //为以后动态服务发现做准备 OnInit(app App, settings *conf.ModuleSettings) OnDestroy() GetApp() App Run(closeSig chan bool) }
Module 基本模块定义
type Option ¶
type Option func(*Options)
Option 配置项
func KillWaitTTL ¶
KillWaitTTL specifies the interval on which to re-register
func RegisterInterval ¶
RegisterInterval specifies the interval on which to re-register
func RegisterTTL ¶
RegisterTTL specifies the TTL to use when registering the service
func SetClientRPChandler ¶ added in v1.1.13
func SetClientRPChandler(t ClientRPCHandler) Option
SetClientRPChandler 配置调用者监控器
func SetRpcCompleteHandler ¶ added in v1.3.99
func SetRpcCompleteHandler(t RpcCompleteHandler) Option
SetServerRPCCompleteHandler 服务RPC执行结果监控器
func SetServerRPCHandler ¶ added in v1.1.14
func SetServerRPCHandler(t ServerRPCHandler) Option
SetServerRPCHandler 配置服务方监控器
func WithLogFile ¶ added in v1.4.13
func WithLogFile(name FileNameHandler) Option
WithLogFile 日志文件名称
type Options ¶
type Options struct { Nats *nats.Conn Version string Debug bool Parse bool //是否由框架解析启动环境变量,默认为true WorkDir string ConfPath string LogDir string BIDir string ProcessID string KillWaitTTL time.Duration Registry registry.Registry Selector selector.Selector // Register loop interval RegisterInterval time.Duration RegisterTTL time.Duration ClientRPChandler ClientRPCHandler ServerRPCHandler ServerRPCHandler RpcCompleteHandler RpcCompleteHandler RPCExpired time.Duration RPCMaxCoroutine int // 自定义日志文件名字 // 主要作用方便k8s映射日志不会被冲突,建议使用k8s pod实现 LogFileName FileNameHandler // 自定义BI日志名字 BIFileName FileNameHandler }
Options 应用级别配置项
type RPCModule ¶
type RPCModule interface { context.Context Module // Deprecated: 因为命名规范问题函数将废弃,请用GetServerID代替 GetServerId() string //模块类型 GetServerID() string //模块类型 // Deprecated: 因为命名规范问题函数将废弃,请用Invoke代替 RpcInvoke(moduleType string, _func string, params ...interface{}) (interface{}, string) Invoke(moduleType string, _func string, params ...interface{}) (interface{}, string) // Deprecated: 因为命名规范问题函数将废弃,请用InvokeNR代替 RpcInvokeNR(moduleType string, _func string, params ...interface{}) error InvokeNR(moduleType string, _func string, params ...interface{}) error // Deprecated: 因为命名规范问题函数将废弃,请用InvokeArgs代替 RpcInvokeArgs(moduleType string, _func string, ArgsType []string, args [][]byte) (interface{}, string) InvokeArgs(moduleType string, _func string, ArgsType []string, args [][]byte) (interface{}, string) // Deprecated: 因为命名规范问题函数将废弃,请用InvokeNRArgs代替 RpcInvokeNRArgs(moduleType string, _func string, ArgsType []string, args [][]byte) error InvokeNRArgs(moduleType string, _func string, ArgsType []string, args [][]byte) error // Deprecated: 因为命名规范问题函数将废弃,请用Call代替 RpcCall(ctx context.Context, moduleType, _func string, param mqrpc.ParamOption, opts ...selector.SelectOption) (interface{}, string) // Call 通用RPC调度函数 // ctx context.Context 上下文,可以设置这次请求的超时时间 // moduleType string 服务名称 // _func string 需要调度的服务方法 // param mqrpc.ParamOption 方法传参 // opts ...selector.SelectOption 服务发现模块过滤,可以用来选择调用哪个服务节点 Call(ctx context.Context, moduleType, _func string, param mqrpc.ParamOption, opts ...selector.SelectOption) (interface{}, string) GetModuleSettings() (settings *conf.ModuleSettings) /** filter 调用者服务类型 moduleType|moduleType@moduleID Type 想要调用的服务类型 */ GetRouteServer(filter string, opts ...selector.SelectOption) (ServerSession, error) GetExecuting() int64 }
RPCModule RPC模块定义
type RPCSerialize ¶
type RPCSerialize interface { /** 序列化 结构体-->[]byte param 需要序列化的参数值 @return ptype 当能够序列化这个值,并且正确解析为[]byte时 返回改值正确的类型,否则返回 ""即可 @return p 解析成功得到的数据, 如果无法解析该类型,或者解析失败 返回nil即可 @return err 无法解析该类型,或者解析失败 返回错误信息 */ Serialize(param interface{}) (ptype string, p []byte, err error) /** 反序列化 []byte-->结构体 ptype 参数类型 与Serialize函数中ptype 对应 b 参数的字节流 @return param 解析成功得到的数据结构 @return err 无法解析该类型,或者解析失败 返回错误信息 */ Deserialize(ptype string, b []byte) (param interface{}, err error) /** 返回这个接口能够处理的所有类型 */ GetTypes() []string }
RPCSerialize 自定义参数序列化接口
type RpcCompleteHandler ¶ added in v1.3.99
type RpcCompleteHandler func(app App, module Module, callInfo *mqrpc.CallInfo, input []interface{}, out []interface{}, execTime time.Duration)
ServerRPCHandler 服务方RPC监控
type ServerRPCHandler ¶ added in v1.1.14
ServerRPCHandler 服务方RPC监控
type ServerSession ¶
type ServerSession interface { // Deprecated: 因为命名规范问题函数将废弃,请用GetID代替 GetId() string GetID() string GetName() string GetRpc() mqrpc.RPCClient // Deprecated: 因为命名规范问题函数将废弃,请用GetRPC代替 GetRPC() mqrpc.RPCClient GetApp() App GetNode() *registry.Node SetNode(node *registry.Node) (err error) Call(ctx context.Context, _func string, params ...interface{}) (interface{}, string) CallNR(_func string, params ...interface{}) (err error) CallArgs(ctx context.Context, _func string, ArgsType []string, args [][]byte) (interface{}, string) CallNRArgs(_func string, ArgsType []string, args [][]byte) (err error) }
ServerSession 服务代理
Click to show internal directories.
Click to hide internal directories.