Documentation ¶
Index ¶
- Constants
- func SearchStrings(strs *[]string, str string) int
- func SubscribeBatch(bus Bus, data interface{}, verify bool, excludes ...string) (func(), error)
- func SubscribeEvent(bus Bus, hdl EventHandler) (func(), error)
- func SubscribeTag(bus Bus, data interface{}, verify bool, tag string) (func(), error)
- type Bus
- type BusController
- type BusPublisher
- type BusSubscriber
- type Client
- func (client *Client) EventBus() Bus
- func (client *Client) Service() *ClientService
- func (client *Client) Start() error
- func (client *Client) Started() bool
- func (client *Client) Stop()
- func (client *Client) Subscribe(topic string, fn interface{}, serverAddr, serverPath string)
- func (client *Client) SubscribeOnce(topic string, fn interface{}, serverAddr, serverPath string)
- type ClientArg
- type ClientService
- type EventBus
- func (bus *EventBus) HasCallback(topic string) bool
- func (bus *EventBus) PassedArguments(funcType reflect.Type, args ...interface{}) ([]reflect.Value, bool)
- func (bus *EventBus) Publish(topic string, args ...interface{})
- func (bus *EventBus) PublishWaitAsync(topic string, args ...interface{}) *sync.WaitGroup
- func (bus *EventBus) Subscribe(topic string, fn interface{}) error
- func (bus *EventBus) SubscribeAsync(topic string, fn interface{}, transactional bool) error
- func (bus *EventBus) SubscribeOnce(topic string, fn interface{}) error
- func (bus *EventBus) SubscribeOnceAsync(topic string, fn interface{}) error
- func (bus *EventBus) Unsubscribe(topic string, handler interface{}) error
- func (bus *EventBus) WaitAsync(wg *sync.WaitGroup)
- type EventHandler
- type EventSubscriber
- type Kind
- type MultiError
- type NetworkBus
- type NetworkBusService
- type Server
- type ServerService
- type SubscribeArg
- type SubscribeType
Constants ¶
const (
// PublishService - Client service method
PublishService = "ClientService.PushEvent"
)
const (
// RegisterService - Server subscribe service method
RegisterService = "ServerService.Register"
)
Variables ¶
This section is empty.
Functions ¶
func SearchStrings ¶
func SubscribeEvent ¶
func SubscribeEvent(bus Bus, hdl EventHandler) (func(), error)
*
* * bus: 总线 * hdl: 订阅的内容
Types ¶
type Bus ¶
type Bus interface { BusController BusSubscriber BusPublisher }
Bus englobes global (subscribe, publish, control) bus behavior
type BusController ¶
BusController defines bus control behavior (checking handler's presence, synchronization)
type BusPublisher ¶
type BusPublisher interface { Publish(topic string, args ...interface{}) PublishWaitAsync(topic string, args ...interface{}) *sync.WaitGroup }
BusPublisher defines publishing-related bus behavior
type BusSubscriber ¶
type BusSubscriber interface { Subscribe(topic string, fn interface{}) error SubscribeAsync(topic string, fn interface{}, transactional bool) error SubscribeOnce(topic string, fn interface{}) error SubscribeOnceAsync(topic string, fn interface{}) error Unsubscribe(topic string, handler interface{}) error }
BusSubscriber defines subscription-related bus behavior
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client - object capable of subscribing to a remote event bus
func (*Client) Service ¶
func (client *Client) Service() *ClientService
func (*Client) SubscribeOnce ¶
SubscribeOnce subscribes once to a topic in a remote event bus
type ClientArg ¶
type ClientArg struct { Args []interface{} Topic string }
ClientArg - object containing event for client to publish locally
type ClientService ¶
type ClientService struct {
// contains filtered or unexported fields
}
ClientService - service object listening to events published in a remote event bus
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus - box for handlers and callbacks.
func (*EventBus) HasCallback ¶
HasCallback returns true if exists any callback subscribed to the topic.
func (*EventBus) PassedArguments ¶
func (bus *EventBus) PassedArguments(funcType reflect.Type, args ...interface{}) ([]reflect.Value, bool)
处理调用的参数
func (*EventBus) Publish ¶
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*EventBus) PublishWaitAsync ¶
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*EventBus) Subscribe ¶
Subscribe subscribes to a topic. Returns error if `fn` is not a function.
func (*EventBus) SubscribeAsync ¶
SubscribeAsync subscribes to a topic with an asynchronous callback Transactional determines whether subsequent callbacks for a topic are run serially (true) or concurrently (false) Returns error if `fn` is not a function.
func (*EventBus) SubscribeOnce ¶
SubscribeOnce subscribes to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.
func (*EventBus) SubscribeOnceAsync ¶
SubscribeOnceAsync subscribes to a topic once with an asynchronous callback Handler will be removed after executing. Returns error if `fn` is not a function.
func (*EventBus) Unsubscribe ¶
Unsubscribe removes callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.
type EventHandler ¶
type EventSubscriber ¶
type MultiError ¶
type MultiError struct {
Errs []error
}
func NewMultiError ¶
func NewMultiError(errs *[]error) *MultiError
func (*MultiError) Error ¶
func (e *MultiError) Error() string
type NetworkBus ¶
NetworkBus - object capable of subscribing to remote event buses in addition to remote event busses subscribing to it's local event bus. Compoed of a server and client
func NewNetworkBus ¶
func NewNetworkBus(address, path string) *NetworkBus
NewNetworkBus - returns a new network bus object at the server address and path
func (*NetworkBus) EventBus ¶
func (networkBus *NetworkBus) EventBus() Bus
EventBus - returns wrapped event bus
func (*NetworkBus) Start ¶
func (networkBus *NetworkBus) Start() error
Start - helper method to serve a network bus service
func (*NetworkBus) Stop ¶
func (networkBus *NetworkBus) Stop()
Stop - signal for the service to stop serving
type NetworkBusService ¶
type NetworkBusService struct {
// contains filtered or unexported fields
}
NetworkBusService - object capable of serving the network bus
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server - object capable of being subscribed to by remote handlers
func (*Server) HasClientSubscribed ¶
func (server *Server) HasClientSubscribed(arg *SubscribeArg) bool
HasClientSubscribed - True if a client subscribed to this server with the same topic
func (*Server) Service ¶
func (server *Server) Service() *ServerService
type ServerService ¶
type ServerService struct {
// contains filtered or unexported fields
}
ServerService - service object to listen to remote subscriptions
func (*ServerService) Register ¶
func (service *ServerService) Register(arg *SubscribeArg, success *bool) error
Register - Registers a remote handler to this event bus for a remote subscribe - a given client address only needs to subscribe once event will be republished in local event bus
type SubscribeArg ¶
type SubscribeArg struct { ClientAddr string ClientPath string ServiceMethod string SubscribeType SubscribeType Topic string }
SubscribeArg - object to hold subscribe arguments from remote event handlers
type SubscribeType ¶
type SubscribeType int
SubscribeType - how the client intends to subscribe
const ( // Subscribe - subscribe to all events SubscribeAll SubscribeType = iota // SubscribeOnce - subscribe to only one event SubscribeOnce )