Documentation
¶
Index ¶
- type ClientRPCHandler
- type FileNameHandler
- type IApp
- type ICtxTransSetApp
- type IModule
- type IRPCModule
- type IServerSession
- type Option
- func BILogDir(v string) Option
- func ConfigKey(v string) Option
- func ConsulAddr(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 RpcCompleteHandler
- type ServerRPCHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientRPCHandler ¶
type ClientRPCHandler func(server registry.Node, rpcinfo *core.RPCInfo, result any, err error, exec_time int64)
ClientRPCHandler 调用方RPC监控
type FileNameHandler ¶
FileNameHandler 自定义日志文件名字
type IApp ¶
type IApp interface {
OnInit() error
OnDestroy() error
Run(mods ...IModule) error
// Config 获取启动配置
Config() conf.Config
// Options 获取应用配置
Options() Options
// Transporter 获取消息传输对象
Transporter() *nats.Conn
// Registrar 获取服务注册对象
Registrar() registry.Registry
// WorkDir 获取进程工作目录
WorkDir() string
// GetProcessEnv 获取应用进程分组ID(dev,test,...)
GetProcessEnv() string
// UpdateOptions 允许再次更新应用配置(before app.Run)
UpdateOptions(opts ...Option) error
// 设置服务路由器(动态转换service名称)
SetServiceRoute(fn func(route string) string) error
// 获取服务实例(通过服务ID|服务类型,可设置selector.WithFilter和selector.WithStrategy)
GetRouteServer(service string, opts ...selector.SelectOption) (IServerSession, error)
// 获取服务实例(通过服务ID(moduleType@id))
GetServerByID(serverID string) (IServerSession, error)
// 获取服务实例(通过服务类型(moduleType),可设置可设置selector.WithFilter和selector.WithStrategy)
GetServerBySelector(serviceName string, opts ...selector.SelectOption) (IServerSession, error)
// 获取多个服务实例(通过服务类型(moduleType))
GetServersByType(serviceName string) []IServerSession
// Call RPC调用(需要等待结果)
Call(ctx context.Context, moduleType, _func string, param mqrpc.ParamOption, opts ...selector.SelectOption) (any, error)
// Call RPC调用(无需等待结果)
CallNR(ctx context.Context, moduleType, _func string, params ...any) error
// Call RPC调用(群发,无需等待结果)
CallBroadcast(ctx context.Context, moduleName, _func string, params ...any)
// 回调(hook)
OnConfigurationLoaded(func()) error // 设置应用启动配置初始化完成后回调
OnModuleInited(func(module IModule)) error // 设置每个模块初始化完成后回调
GetModuleInited() func(module IModule) // 获取每个模块初始化完成后回调函数
OnStartup(func()) error // 设置应用启动完成后回调
OnServiceBreak(_func func(moduleName, serverId string)) error // 设置当模块服务断开删除时回调
}
IApp mqant应用定义
type ICtxTransSetApp ¶
type ICtxTransSetApp interface {
SetApp(IApp)
}
RPC传输时Context中的数据可能会需要赋值跨服务的app(为什么会有这个接口,会循环import)
type IModule ¶
type IModule interface {
GetType() string // 模块类型
Version() string // 模块版本
Run(closeSig chan bool)
OnInit(settings *conf.ModuleSettings) // 所有初始化逻辑都放到Init中, 重载OnInit不可调用基类!(由Init层层调用base.Init)即可
OnDestroy()
OnAppConfigurationLoaded() // 当App初始化时调用,这个接口不管这个模块是否在这个进程运行都会调用
OnConfChanged(settings *conf.ModuleSettings) // 为以后动态服务发现做准备(目前没用)
}
IModule 基本模块定义
type IRPCModule ¶
type IRPCModule interface {
IModule
// 模块服务ID
GetServerID() string
GetModuleSettings() (settings *conf.ModuleSettings)
// 获取服务实例(通过服务ID|服务类型,可设置选择器过滤)
GetRouteServer(service string, opts ...selector.SelectOption) (IServerSession, error) //获取经过筛选过的服务
// 通过服务ID(moduleType@id)获取服务实例
GetServerByID(serverID string) (IServerSession, error)
// 通过服务类型(moduleType)获取服务实例列表
GetServersByType(serviceName string) []IServerSession
// 通过服务类型(moduleType)获取服务实例(可设置选择器)
GetServerBySelector(serviceName string, opts ...selector.SelectOption) (IServerSession, error)
Call(ctx context.Context, moduleType, _func string, params mqrpc.ParamOption, opts ...selector.SelectOption) (any, error)
CallNR(ctx context.Context, moduleType, _func string, params ...any) error
CallBroadcast(ctx context.Context, moduleName, _func string, params ...any)
}
IRPCModule RPC模块定义
type IServerSession ¶
type IServerSession interface {
GetID() string
GetName() string
GetRPC() mqrpc.RPCClient
GetNode() *registry.Node
SetNode(node *registry.Node) (err error)
Call(ctx context.Context, _func string, params ...any) (any, error) // 等待返回结果
CallArgs(ctx context.Context, _func string, argTypes []string, argDatas [][]byte) (any, error) // 内部使用(ctx参数必须装进args中)
CallNR(ctx context.Context, _func string, params ...any) (err error) // 无需等待结果
CallNRArgs(ctx context.Context, _func string, argTypes []string, argDatas [][]byte) (err error) // 内部使用(ctx参数必须装进args中)
}
IServerSession 服务代理
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 ¶
func SetClientRPChandler(t ClientRPCHandler) Option
SetClientRPChandler 配置调用者监控器
func SetRpcCompleteHandler ¶
func SetRpcCompleteHandler(t RpcCompleteHandler) Option
SetServerRPCCompleteHandler 服务RPC执行结果监控器
func SetServerRPCHandler ¶
func SetServerRPCHandler(t ServerRPCHandler) Option
SetServerRPCHandler 配置服务方监控器
type Options ¶
type Options struct {
Version string // app的版本
Debug bool
Parse bool // 是否由框架解析启动环境变量,默认为true
WorkDir string // 工作目录(from startUpArgs.WordDir)
ProcessEnv string // 进程分组名称(from startUpArgs.ProcessEnv)
ConfigKey string // consul configKey(default: config/{env}/server)
ConsulAddr []string // consul addr(from startUpArgs.ConsulAddr)
LogDir string // Log目录(from startUpArgs.LogPath default: ./bin/logs)
BIDir string // BI目录(from startUpArgs.BiPath default: ./bin/bi)
PProfAddr string
KillWaitTTL time.Duration // 服务关闭超时强杀(60s)
Nats *nats.Conn
Registry registry.Registry // 注册服务发现(registry.DefaultRegistry)
Selector selector.Selector // 节点选择器(在Registry基础上)(cache.NewSelector())
RegisterInterval time.Duration // 服务注册发现续约频率(10s)
RegisterTTL time.Duration // 服务注册发现续约生命周期(20s)
ClientRPChandler ClientRPCHandler // 配置RPC调用方监控器(nil)
ServerRPCHandler ServerRPCHandler // 配置RPC服务方监控器(nil)
RpcCompleteHandler RpcCompleteHandler // 配置RPC执行结果监控器(nil)
RPCExpired time.Duration // RPC调用超时(10s)
RPCMaxCoroutine int // 默认0(不限制) 没用
// 自定义日志文件名字(主要作用方便k8s映射日志不会被冲突,建议使用k8s pod实现)
LogFileName FileNameHandler // 日志文件名称(默认):fmt.Sprintf("%s/%v%s%s", logdir, prefix, processID, suffix)
// 自定义BI日志名字
BIFileName FileNameHandler // BI文件名称(默认):fmt.Sprintf("%s/%v%s%s", logdir, prefix, processID, suffix)
}
Options 应用级别配置
type RpcCompleteHandler ¶
type RpcCompleteHandler func(module IModule, callInfo *mqrpc.CallInfo, input []any, out []any, execTime time.Duration)
ServerRPCHandler 服务方RPC监控
type ServerRPCHandler ¶
ServerRPCHandler 服务方RPC监控
Click to show internal directories.
Click to hide internal directories.