class EventStoreClient::Client
Constants
- NoCallMethodOnSubscriber
- WrongExpectedEventVersion
Attributes
broker[R]
connection[RW]
rubocop:enable Metrics/CyclomaticComplexity
error_handler[R]
subscriptions[R]
Public Class Methods
new()
click to toggle source
# File lib/event_store_client/client.rb, line 64 def initialize @threads = [] @connection = EventStoreClient.adapter @error_handler = config.error_handler @broker = Broker.new(connection: connection) @subscriptions = config.subscriptions_repo @subscriptions ||= Subscriptions.new(connection: connection, service: config.service_name) end
Public Instance Methods
link_to(stream:, events:, options: {})
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity
# File lib/event_store_client/client.rb, line 48 def link_to(stream:, events:, options: {}) raise ArgumentError if !stream || stream == '' raise ArgumentError if events.nil? || (events.is_a?(Array) && events.empty?) res = connection.link_to(stream, events, options: options) raise WrongExpectedEventVersion.new(e.message) if res.failure? res.success? end
listen(wait: false)
click to toggle source
# File lib/event_store_client/client.rb, line 43 def listen(wait: false) broker.call(@subscriptions, wait: wait) end
publish(stream:, events:, options: {})
click to toggle source
# File lib/event_store_client/client.rb, line 12 def publish(stream:, events:, options: {}) res = connection.append_to_stream(stream, events, options: options) raise WrongExpectedEventVersion.new(res.failure) if res.failure? res end
read(stream, options: {})
click to toggle source
# File lib/event_store_client/client.rb, line 18 def read(stream, options: {}) if options[:all] connection.read_all_from_stream(stream, options: options) else connection.read(stream, options: options) end end
reset_subscriptions()
click to toggle source
# File lib/event_store_client/client.rb, line 37 def reset_subscriptions return unless @subscriptions.respond_to?(:reset) @subscriptions.reset end
subscribe(subscriber, to: [], options: {})
click to toggle source
# File lib/event_store_client/client.rb, line 26 def subscribe(subscriber, to: [], options: {}) raise NoCallMethodOnSubscriber unless subscriber.respond_to?(:call) @subscriptions.create(subscriber, to, options: options) end
subscribe_to_all(subscriber, filter=nil)
click to toggle source
# File lib/event_store_client/client.rb, line 31 def subscribe_to_all(subscriber, filter=nil) raise NoCallMethodOnSubscriber unless subscriber.respond_to?(:call) @subscriptions.create_or_load(subscriber, filter: filter) end