Class: EventStoreClient::Broker

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/event_store_client/broker.rb

Instance Method Summary collapse

Methods included from Configuration

#config

Instance Method Details

#call(subscriptions, wait: false) ⇒ Object

Distributes known subscriptions to multiple threads

Parameters:

  • (EventStoreClient::Subscriptions)
  • wait (Boolean) (defaults to: false)

    (Optional) Controls if broker should block main app process (useful for debugging)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/event_store_client/broker.rb', line 12

def call(subscriptions, wait: false)
  Signal.trap('TERM') do
    Thread.new { logger&.info('Broker: TERM Signal has been received') }
    threads.each do |thread|
      thread.thread_variable_set(:terminate, true)
    end
    Thread.new { logger&.info('Broker: Terminate variable for subscription threads set') }
  end

  subscriptions.each do |subscription|
    threads << Thread.new do
      subscriptions.listen(subscription)
    end
  end
  threads.each(&:join) if wait
end