Class: Servus::Events::Router
- Inherits:
-
Object
- Object
- Servus::Events::Router
- Defined in:
- lib/servus/events/router.rb
Overview
Abstract base class for event routers.
Routers resolve which services should be invoked when an event fires. The Bus iterates all configured routers (in order), collects the Invocation objects they return, deduplicates by key, and executes.
Servus ships one built-in router — ClassRouter — which reads the invoke declarations from Event classes. Applications can add their own routers (e.g. a data-driven router backed by a database table) by subclassing Router and implementing #resolve.
Configure routers in the Servus initializer:
Servus.configure do |config|
config.routers = [
Servus::Events::ClassRouter.new,
MyApp::DataDrivenRouter.new
]
end
Direct Known Subclasses
Instance Method Summary collapse
-
#resolve(event_name, payload) ⇒ Array<Servus::Events::Invocation>
Resolves which service invocations should run for the given event.
Instance Method Details
#resolve(event_name, payload) ⇒ Array<Servus::Events::Invocation>
Resolves which service invocations should run for the given event.
Implementations must evaluate any conditions (if/unless) internally and return only invocations that will run. The Bus does not perform further filtering.
39 40 41 |
# File 'lib/servus/events/router.rb', line 39 def resolve(event_name, payload) raise NotImplementedError, "#{self.class}#resolve must be implemented" end |