Class: Akasha::AsyncEventRouter

Inherits:
EventRouterBase show all
Defined in:
lib/akasha/async_event_router.rb

Overview

Event router working that can run in the background, providing eventual consistency. Can use the same EventListeners as the synchronous EventRouter.

Constant Summary collapse

DEFAULT_POLL_SECONDS =
2
DEFAULT_PAGE_SIZE =
20
DEFAULT_PROJECTION_STREAM =
'AsyncEventRouter'.freeze
DEFAULT_CHECKPOINT_STRATEGY =
Akasha::Checkpoint::MetadataCheckpoint
STREAM_NAME_SEP =
'-'.freeze

Instance Method Summary collapse

Methods inherited from EventRouterBase

#initialize, #register_event_listener, #route

Constructor Details

This class inherits a constructor from Akasha::EventRouterBase

Instance Method Details

#connect!(repository, projection_name: nil, checkpoint_strategy: DEFAULT_CHECKPOINT_STRATEGY, page_size: DEFAULT_PAGE_SIZE, poll: DEFAULT_POLL_SECONDS) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/akasha/async_event_router.rb', line 14

def connect!(repository, projection_name: nil,
             checkpoint_strategy: DEFAULT_CHECKPOINT_STRATEGY,
             page_size: DEFAULT_PAGE_SIZE, poll: DEFAULT_POLL_SECONDS)
  projection_name = projection_name(repository) if projection_name.nil?
  repository.merge_all_by_event(into: projection_name,
                                only: registered_event_names)
  projection_stream = repository.store.streams[projection_name]
  checkpoint = checkpoint_strategy.is_a?(Class) ? checkpoint_strategy.new(projection_stream) : checkpoint_strategy
  Thread.new do
    run_forever(projection_stream, checkpoint, page_size, poll)
  end
end