Class: CDC::Core::Router
- Inherits:
-
Object
- Object
- CDC::Core::Router
- Defined in:
- lib/cdc/core/router.rb
Overview
Routes CDC work items to the appropriate handler.
Router keeps the dispatch vocabulary in core while leaving execution strategy to the caller. It can route single change events, transaction envelopes, and arrays of events.
Instance Attribute Summary collapse
- #observer ⇒ #process, ... readonly
- #processor ⇒ #process, ... readonly
- #transaction_processor ⇒ #process, ... readonly
Instance Method Summary collapse
-
#initialize(processor:, transaction_processor: nil, observer: NullObserver::INSTANCE) ⇒ Router
constructor
Build a router.
-
#process(item) ⇒ Object
Process a CDC work item.
Constructor Details
#initialize(processor:, transaction_processor: nil, observer: NullObserver::INSTANCE) ⇒ Router
Build a router.
21 22 23 24 25 |
# File 'lib/cdc/core/router.rb', line 21 def initialize(processor:, transaction_processor: nil, observer: NullObserver::INSTANCE) @processor = processor @transaction_processor = transaction_processor @observer = observer || NullObserver::INSTANCE end |
Instance Attribute Details
#observer ⇒ #process, ... (readonly)
14 15 16 |
# File 'lib/cdc/core/router.rb', line 14 def observer @observer end |
#processor ⇒ #process, ... (readonly)
14 15 16 |
# File 'lib/cdc/core/router.rb', line 14 def processor @processor end |
#transaction_processor ⇒ #process, ... (readonly)
14 15 16 |
# File 'lib/cdc/core/router.rb', line 14 def transaction_processor @transaction_processor end |
Instance Method Details
#process(item) ⇒ Object
Process a CDC work item.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cdc/core/router.rb', line 32 def process(item) observer.dispatch_started(item) case item when ChangeEvent result = processor.process(item) observe_result(result) result when TransactionEnvelope route_transaction(item) when Array route_many(item) else raise UnsupportedWorkItemError, "unsupported CDC work item: #{item.class}" end end |