Documentation ¶
Overview ¶
Package idlrpc rpc-backend-go framework interface
Index ¶
- Constants
- func PackNoRpcProtocol(rawData []byte) ([]byte, error)
- func PackPlatoProtocol(serviceUUID uint64, methodID uint32, protoMessage proto.Message) ([]byte, error)
- func RpcStrError(errorCode uint32) error
- type CallInfo
- type CallUuid
- type ContextIterator
- type ContextKV
- type EventCallBack
- type IMessageHandler
- type IProxy
- type IProxyHandler
- type IPublisher
- type IRpc
- type ISDK
- type IService
- type IServiceContext
- type IStub
- type ISubscriber
- type IUuidFactory
- type Option
- func WithCallTrace(open bool) Option
- func WithLocation(location *time.Location) Option
- func WithLogger(logger log.ILogger) Option
- func WithMaxTaskCount(count int) Option
- func WithMessageHandler(handler IMessageHandler) Option
- func WithServiceContext(ctx IServiceContext) Option
- func WithStackTrace(open bool) Option
- func WithUuidFactory(uid IUuidFactory) Option
- type Options
- type PackageInfo
- type ProxyBase
- func (base *ProxyBase) Cancel(event string) error
- func (base *ProxyBase) GetGlobalIndex() protocol.GlobalIndexType
- func (base *ProxyBase) GetID() ProxyId
- func (base *ProxyBase) GetIdentityID() string
- func (base *ProxyBase) GetRpc() IRpc
- func (base *ProxyBase) GetTargetID() uint32
- func (base *ProxyBase) GetTransport() transport.ITransport
- func (base *ProxyBase) IsConnected() bool
- func (base *ProxyBase) NotifyEvent(subId string, data []byte)
- func (base *ProxyBase) SetGlobalIndex(index protocol.GlobalIndexType)
- func (base *ProxyBase) SetID(id ProxyId)
- func (base *ProxyBase) SetRpc(r IRpc)
- func (base *ProxyBase) SetSubscriber(s ISubscriber)
- func (base *ProxyBase) SetTargetID(id uint32)
- func (base *ProxyBase) SetTransport(trans transport.ITransport)
- func (base *ProxyBase) Subscribe(event string, data []byte, callback EventCallBack) error
- type ProxyCreator
- type ProxyId
- type ProxyManager
- type ProxyMap
- type RpcCallManager
- func (cm *RpcCallManager) CreateAsyncCall(ctx IServiceContext, callBack proxy.RpcCallBack, oneway bool, ...) *RpcCallWrapper
- func (cm *RpcCallManager) CreateSyncCall(oneway bool, opts ...proxy.RpcCallOption) *RpcCallWrapper
- func (cm *RpcCallManager) Destroy(callId uint32)
- func (cm *RpcCallManager) GenCallID() uint32
- func (cm *RpcCallManager) Get(callId uint32) *RpcCallWrapper
- type RpcCallWrapper
- type RpcContext
- func (c *RpcContext) Clone() *RpcContext
- func (c *RpcContext) Continue()
- func (c *RpcContext) Finish(any interface{}, err error) error
- func (c *RpcContext) GetGlobalIndex() protocol.GlobalIndexType
- func (c *RpcContext) GetRequestContext() ContextKV
- func (c *RpcContext) GetResponseContext() ContextKV
- func (c *RpcContext) GetResponseValue(key string) (string, bool)
- func (c *RpcContext) GetUserContext() ContextKV
- func (c *RpcContext) GetValue(key string) (string, bool)
- func (c *RpcContext) IsContinue() bool
- func (c *RpcContext) SetContext(key string, value string)
- func (c *RpcContext) SetResponseContext(key string, value string)
- func (c *RpcContext) SetUserContext(key string, value string)
- type SdkCreateHandle
- type ServiceCache
- type ServiceCreator
- type ServiceStatus
- type StubCreator
- type StubManager
- func (m *StubManager) Add(ctx IServiceContext, impl IStub) (err error)
- func (m *StubManager) AddSubInfo(subId string, sUid SvcUuid) error
- func (m *StubManager) GeneUuid() CallUuid
- func (m *StubManager) Get(uuid SvcUuid) *stubWrapper
- func (m *StubManager) GetSubService(subId string) *stubWrapper
- func (m *StubManager) Init(logger log.ILogger)
- func (m *StubManager) RemoveSubInfo(subId string)
- func (m *StubManager) Tick()
- func (m *StubManager) UnInit()
- type SubStubMap
- type SvcUuid
- type Trans2Proxy
Constants ¶
const ( RpcNotInit = iota RpcRunning RpcClosed )
const ( ProxyConnected = iota ProxyDisconnected )
const (
InvalidGlobalIndex = 0
)
Variables ¶
This section is empty.
Functions ¶
func PackNoRpcProtocol ¶ added in v0.5.12
func PackPlatoProtocol ¶ added in v0.5.12
func PackPlatoProtocol(serviceUUID uint64, methodID uint32, protoMessage proto.Message) ([]byte, error)
PackPlatoProtocol 生成RPC调用请求协议
func RpcStrError ¶ added in v0.5.7
RpcStrError 将错误码转换为 error
Types ¶
type CallInfo ¶ added in v0.5.4
type CallInfo struct {
// contains filtered or unexported fields
}
CallInfo remote call data
func (*CallInfo) GetServiceUUID ¶ added in v0.5.4
func (*CallInfo) GlobalIndex ¶ added in v0.5.4
func (sc *CallInfo) GlobalIndex() protocol.GlobalIndexType
type ContextIterator ¶ added in v0.5.4
type EventCallBack ¶ added in v0.5.0
EventCallBack will be called while subscriber receive sub event
type IMessageHandler ¶ added in v0.5.3
type IMessageHandler interface { OnLoggedOut(index protocol.GlobalIndexType) OnIdentityNotify(transport transport.ITransport, identityID string, identityTag string) OnRawMessage(transport transport.ITransport, msg []byte) }
type IProxy ¶ added in v0.3.2
type IProxy interface { // GetUUID service uuid // @detail get service uuid id which generated by rpc-repo GetUUID() uint64 // GetSignature // get method human-readable name GetSignature(uint32) string // GetID //get proxy instance ID, priority delivery service instance GetID() ProxyId // SetID // set proxy instance ID SetID(ProxyId) // SetTargetID // last return service id, maybe some service box need SetTargetID(uint32) // GetTargetID // return last return service id GetTargetID() uint32 // GetGlobalIndex // return proxy global index GetGlobalIndex() protocol.GlobalIndexType //GetIdentityID will return the identity of the underlying connection. GetIdentityID() string // SetGlobalIndex // set proxy global index SetGlobalIndex(indexType protocol.GlobalIndexType) //NotifyEvent will transport sub event data NotifyEvent(string, []byte) // IsOneWay oneway //@detail is one way function which not wait for return //@param method id IsOneWay(uint32) bool // GetSrvName //@detail get proxy name GetSrvName() string // SetTransport // @detail set transport SetTransport(transport.ITransport) //SetSubscriber set subscriber to proxy SetSubscriber(ISubscriber) //Subscribe will subscribe the event of target service Subscribe(string, []byte, EventCallBack) error //Cancel will cancel subscribe of target event Cancel(string) error // GetTransport // return transport GetTransport() transport.ITransport // IsConnected // check transport valid state IsConnected() bool // SetRpc set rpc instance to proxy SetRpc(IRpc) // GetRpc get rpc instance from proxy GetRpc() IRpc // contains filtered or unexported methods }
IProxy user's idl proxy interface, using as client to call remote function; rpc framework set transport to it
type IProxyHandler ¶ added in v0.3.4
type IProxyHandler interface {
OnRelay(trans transport.ITransport, header *protocol.RpcMsgHeader) error
}
type IPublisher ¶ added in v0.5.0
type IRpc ¶ added in v0.3.3
type IRpc interface { Init(...Option) error // Start rpc framework,init data and start some goroutine Start() error // Tick Calls the main loop in the user master coroutine。 Tick() error // ShutDown close rpc framework close ShutDown() error // Options options get rpc options Options() *Options // OnMessage deal network message OnMessage(IServiceContext) error // OnProxyMessage trans proxy message to inside service OnProxyMessage(transport.ITransport, IProxyHandler) error // RegisterService register user impl service struct to framework RegisterService(IService) error // SyncCall service proxy call remote sync SyncCall(IServiceContext, IProxy, uint32, uint32, int32, proto.Message) ([]byte, error) // AsyncCall service proxy call remote async AsyncCall(IServiceContext, IProxy, uint32, uint32, int32, proto.Message, proxy.RpcCallBack) error //Publish will notify all subscriber with event's data Publish(uuid SvcUuid, serviceID int32, event string, data []byte) error // GetProxyFromPeer get proxy by stub call GetProxyFromPeer(ctx IServiceContext, uuid uint64) (IProxy, error) // GetServiceProxy get service proxy GetServiceProxy(uuid uint64, trans transport.ITransport) (IProxy, error) // GetExtraProxy get extra service proxy GetExtraProxy(uuid uint64, globalIndex protocol.GlobalIndexType, trans transport.ITransport) (IProxy, error) // AddProxyCreator add proxy creator AddProxyCreator(uuid uint64, pc ProxyCreator) error // AddStubCreator add stub creator AddStubCreator(uuid uint64, bc StubCreator) error }
func CreateRpcFramework ¶ added in v0.3.3
func CreateRpcFramework() IRpc
type IService ¶ added in v0.3.1
type IService interface { // GetUUID service uuid, generated by rpc-repo GetUUID() uint64 // GetNickName return custom service nickname ! GetNickName() string // OnAfterFork init service by framework, user can init some custom data in this function OnAfterFork(ctx IServiceContext) bool // OnTick tick your service the same goroutine OnTick() bool //OnSubscribe will be triggered when a subscriber subscribes to an event OnSubscribe(string, string, []byte) error // OnCancel e triggered when a subscriber cancel OnCancel(string, string) error // OnBeforeDestroy before service unload, you can clean your own data in this func OnBeforeDestroy() bool }
IService user custom service framework interface
type IServiceContext ¶ added in v0.5.4
type IServiceContext interface { GetTransport() transport.ITransport // GetGlobalIndex get external connection id GetGlobalIndex() protocol.GlobalIndexType // GetIdentityID will return the identity id of the source of the RPC call GetIdentityID() string // GetIdentityTag will return the identity tag of the source of the RPC call GetIdentityTag() string // GetProxyFromPeer Gets the proxy utility function of the peer service GetProxyFromPeer(uuid uint64) IProxy // GetProxy get the Proxy for the service GetProxy(uuid uint64) IProxy // GetProxyWithNickname get the Proxy for the service by nickname GetProxyWithNickname(uuid uint64, name string) IProxy // GetValue returns the value for the given key, ie: (value, true). // If the value does not exist it returns (nil, false) GetValue(string) (string, bool) // GetRequestContext will return the request context kv map GetRequestContext() ContextKV // GetResponseValue returns the value for the given key in the response context GetResponseValue(string) (string, bool) // GetResponseContext will return the response context kv map GetResponseContext() ContextKV // GetUserContext will return the user context kv map GetUserContext() ContextKV // SetContext will set the context of the RPC request SetContext(string, string) // SetUserContext Set the user context to be passed on the next RPC call. Null character will delete the Key. SetUserContext(string, string) // SetResponseContext Set the response context to be passed on the RPC response. SetResponseContext(string, string) // Debug Tool function, automatically append call information, print Debug level logs Debug(string, ...interface{}) // Info Tool function, automatically append call information, print INFO level logs Info(string, ...interface{}) // Warning Tool function, automatically append call information, print WARNING level logs Warning(string, ...interface{}) // Error Tool function, automatically append call information, print ERROR level logs Error(string, ...interface{}) // Clone a new context that does not contain user-defined key values. Clone() IServiceContext // Continue When an RPC method returns, it is not immediately returned to the caller. The current RPC call ends only after the Finish method is called. Continue() // IsContinue Whether to return to the calling end immediately after the RPC method returns IsContinue() bool // Finish Ends the RPC call and returns. If the RPC call times out, an error is returned. Finish(interface{}, error) error // contains filtered or unexported methods }
IServiceContext The context information needed to communicate between services
type IStub ¶ added in v0.3.2
type IStub interface { //GetUUID service uuid, generate by rpc-repo GetUUID() SvcUuid //GetServiceName service name GetServiceName() string //GetSignature method human-readable name GetSignature(methodId uint32) string //GetMultipleNum will return the number of concurrent coroutines for the service GetMultipleNum() uint32 //IsOneWay that returns whether the method is oneway IsOneWay(uint32) bool // GetTimeout will return the timeout config of the method GetTimeout(uint32) uint32 // Call will call the microservice method and returns the serialized data with the error code Call(IServiceContext, uint32, []byte) ([]byte, error) // Return In non-immediate mode, the call can be returned to the sender Return(IServiceContext, uint32, interface{}, error) ([]byte, error) //OnAfterFork invoke by framework after spawned //init service data or load db data in this function OnAfterFork(IServiceContext) bool //OnBeforeDestroy invoke by framework before uninitialized //clean service data in this function OnBeforeDestroy() bool //OnTick tick by service manager in logic tick OnTick() bool //GetStatus get service status //TODO: for hot update GetStatus() ServiceStatus //SetStatus set service status SetStatus(ServiceStatus) //OnSub will notify service sub info OnSub(string, string, []byte) error //OnCancel will notify subscriber remove sub OnCancel(string, string) error }
IStub rpc stub of service's side
type ISubscriber ¶ added in v0.5.0
type ISubscriber interface { //Subscribe will send sub request to target service Subscribe(uint32, string, []byte, EventCallBack) error //OnNotify will be called while publisher pub event OnNotify(string, []byte) error //Cancel will remove sub info from publisher Cancel(uint32, string) error //CancelAll will remove all sub info from publisher CancelAll(uint32) error }
ISubscriber is the manager of sub request which been mount to proxy instance
type IUuidFactory ¶ added in v0.5.0
type IUuidFactory interface { //NewUuid will generate string uuid with 32 characters NewUuid() string }
type Option ¶ added in v0.3.4
type Option func(*Options)
func WithCallTrace ¶ added in v0.4.16
func WithLocation ¶ added in v0.5.7
func WithLogger ¶ added in v0.3.4
func WithMaxTaskCount ¶ added in v0.5.7
func WithMessageHandler ¶ added in v0.5.3
func WithMessageHandler(handler IMessageHandler) Option
func WithServiceContext ¶ added in v0.5.4
func WithServiceContext(ctx IServiceContext) Option
func WithStackTrace ¶ added in v0.3.4
func WithUuidFactory ¶ added in v0.5.0
func WithUuidFactory(uid IUuidFactory) Option
type Options ¶ added in v0.3.4
type Options struct {
// contains filtered or unexported fields
}
func (*Options) StackTrace ¶ added in v0.4.16
type PackageInfo ¶ added in v0.3.4
type PackageInfo struct { ServiceUUID uint64 //service uuid Creator SdkCreateHandle //Sdk Creator handle }
PackageInfo service package information
type ProxyBase ¶ added in v0.3.2
type ProxyBase struct {
// contains filtered or unexported fields
}
ProxyBase proxy common struct impl
func (*ProxyBase) GetGlobalIndex ¶ added in v0.3.4
func (base *ProxyBase) GetGlobalIndex() protocol.GlobalIndexType
func (*ProxyBase) GetIdentityID ¶ added in v0.5.3
func (*ProxyBase) GetTargetID ¶ added in v0.3.2
func (*ProxyBase) GetTransport ¶ added in v0.3.2
func (base *ProxyBase) GetTransport() transport.ITransport
func (*ProxyBase) IsConnected ¶ added in v0.3.2
func (*ProxyBase) NotifyEvent ¶ added in v0.5.0
func (*ProxyBase) SetGlobalIndex ¶ added in v0.3.4
func (base *ProxyBase) SetGlobalIndex(index protocol.GlobalIndexType)
func (*ProxyBase) SetSubscriber ¶ added in v0.5.0
func (base *ProxyBase) SetSubscriber(s ISubscriber)
func (*ProxyBase) SetTargetID ¶ added in v0.3.2
func (*ProxyBase) SetTransport ¶ added in v0.3.2
func (base *ProxyBase) SetTransport(trans transport.ITransport)
SetTransport set network message transport called by creator
type ProxyCreator ¶ added in v0.3.2
type ProxyCreator func(transport.ITransport) IProxy
ProxyCreator proxy creator, one client may connect to differently service
type ProxyManager ¶ added in v0.3.2
type ProxyManager struct {
// contains filtered or unexported fields
}
ProxyManager manager connect proxy for rpc framework, multiple may be read & write TODO add transport id 2 service uid cache
func (*ProxyManager) Add ¶ added in v0.3.2
func (p *ProxyManager) Add(proxy IProxy) error
func (*ProxyManager) Destroy ¶ added in v0.3.2
func (p *ProxyManager) Destroy(proxyId ProxyId) error
func (*ProxyManager) GeneProxyId ¶ added in v0.3.2
func (p *ProxyManager) GeneProxyId() ProxyId
type RpcCallManager ¶ added in v0.5.7
type RpcCallManager struct {
// contains filtered or unexported fields
}
RpcCallManager rpc 调用管理器,用于管理同步和异步的RPC调用请求
func NewRpcCallManager ¶ added in v0.5.7
func NewRpcCallManager() *RpcCallManager
func (*RpcCallManager) CreateAsyncCall ¶ added in v0.5.7
func (cm *RpcCallManager) CreateAsyncCall(ctx IServiceContext, callBack proxy.RpcCallBack, oneway bool, opts ...proxy.RpcCallOption) *RpcCallWrapper
func (*RpcCallManager) CreateSyncCall ¶ added in v0.5.7
func (cm *RpcCallManager) CreateSyncCall(oneway bool, opts ...proxy.RpcCallOption) *RpcCallWrapper
func (*RpcCallManager) Destroy ¶ added in v0.5.7
func (cm *RpcCallManager) Destroy(callId uint32)
func (*RpcCallManager) GenCallID ¶ added in v0.5.7
func (cm *RpcCallManager) GenCallID() uint32
func (*RpcCallManager) Get ¶ added in v0.5.7
func (cm *RpcCallManager) Get(callId uint32) *RpcCallWrapper
type RpcCallWrapper ¶ added in v0.5.7
type RpcCallWrapper struct {
// contains filtered or unexported fields
}
RpcCallWrapper rpc call 包装,用于保存调用上下文,防止在闭包中被垃圾回收
func (*RpcCallWrapper) SetErrorCode ¶ added in v0.5.7
func (rc *RpcCallWrapper) SetErrorCode(errorCode uint32)
type RpcContext ¶ added in v0.5.4
type RpcContext struct {
// contains filtered or unexported fields
}
func (*RpcContext) Clone ¶ added in v0.5.5
func (c *RpcContext) Clone() *RpcContext
func (*RpcContext) Continue ¶ added in v0.5.7
func (c *RpcContext) Continue()
func (*RpcContext) Finish ¶ added in v0.5.7
func (c *RpcContext) Finish(any interface{}, err error) error
func (*RpcContext) GetGlobalIndex ¶ added in v0.5.4
func (c *RpcContext) GetGlobalIndex() protocol.GlobalIndexType
func (*RpcContext) GetRequestContext ¶ added in v0.5.4
func (c *RpcContext) GetRequestContext() ContextKV
func (*RpcContext) GetResponseContext ¶ added in v0.5.4
func (c *RpcContext) GetResponseContext() ContextKV
func (*RpcContext) GetResponseValue ¶ added in v0.5.4
func (c *RpcContext) GetResponseValue(key string) (string, bool)
func (*RpcContext) GetUserContext ¶ added in v0.5.4
func (c *RpcContext) GetUserContext() ContextKV
func (*RpcContext) GetValue ¶ added in v0.5.4
func (c *RpcContext) GetValue(key string) (string, bool)
func (*RpcContext) IsContinue ¶ added in v0.5.7
func (c *RpcContext) IsContinue() bool
func (*RpcContext) SetContext ¶ added in v0.5.4
func (c *RpcContext) SetContext(key string, value string)
func (*RpcContext) SetResponseContext ¶ added in v0.5.4
func (c *RpcContext) SetResponseContext(key string, value string)
func (*RpcContext) SetUserContext ¶ added in v0.5.4
func (c *RpcContext) SetUserContext(key string, value string)
type SdkCreateHandle ¶ added in v0.3.4
SdkCreateHandle rpc sdk creator, return sdk instance
type ServiceCache ¶ added in v0.3.2
type ServiceCache map[SvcUuid]*stubWrapper
ServiceCache service storage struct
type ServiceCreator ¶ added in v0.3.1
type ServiceCreator func(interface{}) IService
ServiceCreator service creator
type ServiceStatus ¶ added in v0.3.2
type ServiceStatus uint32
const ( SERVICE_RESOLVED ServiceStatus = iota + 1 //ready for servicing SERVICE_UPDATING //stop receive message, wait for update )
type StubCreator ¶ added in v0.3.2
type StubCreator func(v interface{}) IStub
StubCreator stub factory
type StubManager ¶ added in v0.3.2
type StubManager struct {
// contains filtered or unexported fields
}
StubManager stub manager, manager registered service
func (*StubManager) Add ¶ added in v0.3.2
func (m *StubManager) Add(ctx IServiceContext, impl IStub) (err error)
func (*StubManager) AddSubInfo ¶ added in v0.5.0
func (m *StubManager) AddSubInfo(subId string, sUid SvcUuid) error
func (*StubManager) GeneUuid ¶ added in v0.3.2
func (m *StubManager) GeneUuid() CallUuid
func (*StubManager) Get ¶ added in v0.3.2
func (m *StubManager) Get(uuid SvcUuid) *stubWrapper
func (*StubManager) GetSubService ¶ added in v0.5.0
func (m *StubManager) GetSubService(subId string) *stubWrapper
func (*StubManager) Init ¶ added in v0.3.2
func (m *StubManager) Init(logger log.ILogger)
func (*StubManager) RemoveSubInfo ¶ added in v0.5.0
func (m *StubManager) RemoveSubInfo(subId string)
func (*StubManager) Tick ¶ added in v0.3.2
func (m *StubManager) Tick()
func (*StubManager) UnInit ¶ added in v0.3.4
func (m *StubManager) UnInit()
type SubStubMap ¶ added in v0.5.0
type Trans2Proxy ¶ added in v0.3.2
Source Files ¶
- application.go
- context.go
- idlrpc.go
- idlrpc_impl.go
- message_handler.go
- options.go
- package_info.go
- proxy.go
- proxy_handler.go
- proxy_manager.go
- publisher.go
- publisher_impl.go
- rpc_call_manager.go
- service.go
- stub.go
- stub_call.go
- stub_manager.go
- stub_wrapper.go
- subscriber.go
- subscriber_impl.go
- task.go
- timer_manager.go