Documentation ¶
Index ¶
- Variables
- type Consumer
- type Context
- type Engine
- func (eng *Engine) AddRoute(topic string, route Route) (Producer, error)
- func (eng *Engine) ContainsConsumer(id *string) bool
- func (eng *Engine) ContainsTopic(topic *string) bool
- func (eng *Engine) CreateTopic(cfg *TopicCfg) error
- func (eng *Engine) DeleteTopic(topicId string)
- func (eng *Engine) GetModuleMeta(name string) interface{}
- func (eng *Engine) Register(sub Consumer)
- func (eng *Engine) SetModuleMeta(name string, data interface{}) error
- func (eng *Engine) Start() error
- func (eng *Engine) Stop() error
- func (eng *Engine) Submit(id string, topic string, data interface{}) error
- func (eng *Engine) SubmitEvent(event Event) error
- func (eng *Engine) SubscribeTo(topicId string, consumers ...string) error
- func (eng *Engine) UseModule(mod Module, topics []*TopicCfg)
- func (eng *Engine) WithCallbacks(cbs EngineCallbacks) *Engine
- func (eng *Engine) WithTopics(topics []*TopicCfg) *Engine
- type EngineCallbacks
- type Event
- type EventRecvr
- type Module
- type ModulePane
- type Producer
- type Route
- type TopicCfg
Constants ¶
This section is empty.
Variables ¶
var ErrEngineAlreadyRunning = errors.New("engine already running")
var ErrEngineDuplicateTopic = errors.New("duplicate topic")
var ErrEngineNotRunning = errors.New("engine not running")
var ErrEngineUnknownConsumer = errors.New("unknown consumer")
var ErrEngineUnknownModule = errors.New("unknown module")
var ErrEngineUnknownTopic = errors.New("unknown topic")
var ErrTopicNoSubscriberFound = errors.New("no subscriber found")
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer struct { Id string Fn EventRecvr }
The receiver of events, potentially subscribed to multiple topics
type Context ¶ added in v0.2.1
type Context struct {
Event *Event
}
Context hands the event that has occurred along with a producer to publish back onto the engine. Since there is no connection directly to the sender, the state of the conversation must be saved to track state over time if so desired.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) AddRoute ¶ added in v0.2.1
A route is an abstraction over consumer/topic/producer to streamline the engine interaction for smaller and/or simpler use-cases than a module. Given the nature and purpose of Nerv, the producer handed back can be called from any thread at any time worry-free as long as the engine is running
func (*Engine) ContainsConsumer ¶
func (*Engine) ContainsTopic ¶
func (*Engine) CreateTopic ¶
func (*Engine) DeleteTopic ¶
func (*Engine) GetModuleMeta ¶ added in v0.2.0
func (*Engine) SetModuleMeta ¶ added in v0.2.0
Store a piece of meta information for a module. This can help users track information about their own modules and permit inter-module communication of state
func (*Engine) SubmitEvent ¶
func (*Engine) SubscribeTo ¶
Does not check for duplicate subscriptions
func (*Engine) WithCallbacks ¶
func (eng *Engine) WithCallbacks(cbs EngineCallbacks) *Engine
func (*Engine) WithTopics ¶
type EngineCallbacks ¶
type EngineCallbacks struct { RegisterCb EventRecvr NewTopicCb EventRecvr ConsumeCb EventRecvr SubmitCb EventRecvr }
type Event ¶
type Event struct { Spawned time.Time `json:spawned` Topic string `json:topic` Producer string `json:producer` Data interface{} `json:data` }
Event structure that is pushed through the event engine and delivered to the subscriber(s) of topics
type Module ¶
type Module interface { GetName() string RecvModulePane(pane *ModulePane) Start() error Shutdown() }
Interface used in nerv engine to manage modules loaded in by the user
type ModulePane ¶ added in v0.2.0
type ModulePane struct { // Retrieve whatever meta-data the users stored // with the module GetModuleMeta func(moduleName string) interface{} // Subscribe a set of consumers to a topic. If register is TRUE, then the // engine will be momentarily locked to ensure that the consumer is registered // as subscription requires a registered consumer. It is safe to always pass TRUE // but it map cause performance overhead if its called a lot as such SubscribeTo func(topic string, consumers []Consumer, register bool) error // Permits module to submit raw data as an event onto // its associated topics as its own producer, where consumers // registered to that function will recieve it SubmitTo func(topic string, data interface{}) // Place an event onto the bus from the module that may or may // not go to consumers of the module. This function is useful // for fowarding events through a module without obfuscating // the original event SubmitEvent EventRecvr }
Interface for module to take action without access to engine object
type Producer ¶ added in v0.2.1
type Producer func(data interface{}) error
Generalized "producer" that can be set to publish to an event system in different ways (remotely, locally, to multople topics, etc)
type Route ¶ added in v0.2.1
type Route func(c *Context)
A route is just a context receiver that can be handed around when a "Route" is added to an engine. These "routes" are a simple abstraction over the topic/producer/consumer module that makes it simple to leverage the eventing system in an application for smaller taskes without requiring the implementation of an entire module