Class: EventSourcery::EventStore::Subscription
- Inherits:
-
Object
- Object
- EventSourcery::EventStore::Subscription
- Defined in:
- lib/event_sourcery/event_store/subscription.rb
Overview
This allows Event Stream Processors (ESPs) to subscribe to an event store, and be notified when new events are added.
Instance Method Summary collapse
-
#initialize(event_store:, poll_waiter:, from_event_id:, event_types: nil, on_new_events:, subscription_master:, events_table_name: :events, batch_size: EventSourcery.config.subscription_batch_size) ⇒ Subscription
constructor
A new instance of Subscription.
-
#start ⇒ Object
Start listening for new events.
Constructor Details
#initialize(event_store:, poll_waiter:, from_event_id:, event_types: nil, on_new_events:, subscription_master:, events_table_name: :events, batch_size: EventSourcery.config.subscription_batch_size) ⇒ Subscription
Returns a new instance of Subscription.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/event_sourcery/event_store/subscription.rb', line 15 def initialize(event_store:, poll_waiter:, from_event_id:, event_types: nil, on_new_events:, subscription_master:, events_table_name: :events, batch_size: EventSourcery.config.subscription_batch_size) @event_store = event_store @from_event_id = from_event_id @poll_waiter = poll_waiter @event_types = event_types @on_new_events = on_new_events @subscription_master = subscription_master @current_event_id = from_event_id - 1 @batch_size = batch_size end |
Instance Method Details
#start ⇒ Object
Start listening for new events. This method will continue to listen for new events until a shutdown is requested through the subscription_master provided.
37 38 39 40 41 42 43 |
# File 'lib/event_sourcery/event_store/subscription.rb', line 37 def start catch(:stop) do @poll_waiter.poll do read_events end end end |