Class: EventSourcery::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/event_sourcery/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Config.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/event_sourcery/config.rb', line 36

def initialize
  @on_unknown_event = proc { |event, aggregate|
    raise AggregateRoot::UnknownEventError, "#{event.type} is unknown to #{aggregate.class.name}"
  }
  @on_event_processor_error = proc { |exception, processor_name|
    # app specific custom logic ie. report to an error reporting service like Rollbar.
  }
  @event_builder = nil
  @event_type_serializer = EventStore::EventTypeSerializers::Underscored.new
  @error_handler_class = EventProcessing::ErrorHandlers::ConstantRetry
  @subscription_batch_size = 1000
end

Instance Attribute Details

#error_handler_classObject

Returns EventProcessing::ErrorHandlers::ConstantRetry.

Returns:

  • EventProcessing::ErrorHandlers::ConstantRetry



26
27
28
# File 'lib/event_sourcery/config.rb', line 26

def error_handler_class
  @error_handler_class
end

#event_body_serializerObject

The event body serializer used by the default event builder (EventStore::EventBuilder). By default EventBodySerializer will be used. Provide a custom serializer here to change how the event body is serialized.



67
68
69
70
71
72
# File 'lib/event_sourcery/config.rb', line 67

def event_body_serializer
  @event_body_serializer ||= EventBodySerializer.new
    .add(Hash, EventBodySerializer::HashSerializer)
    .add(Array, EventBodySerializer::ArraySerializer)
    .add(Time, &:iso8601)
end

#event_builderObject

The event builder used by an event store to build event instances. By default EventStore::EventBuilder will be used. Provide a custom builder here to change how an event is built.



60
61
62
# File 'lib/event_sourcery/config.rb', line 60

def event_builder
  @event_builder || EventStore::EventBuilder.new(event_type_serializer: @event_type_serializer)
end

#event_type_serializerObject

Returns EventStore::EventTypeSerializers::Underscored.

Returns:

  • EventStore::EventTypeSerializers::Underscored



23
24
25
# File 'lib/event_sourcery/config.rb', line 23

def event_type_serializer
  @event_type_serializer
end

#loggerObject

Logger instance used by EventSourcery. By default EventSourcery will log to STDOUT with a log level of Logger::DEBUG



51
52
53
54
55
# File 'lib/event_sourcery/config.rb', line 51

def logger
  @logger ||= ::Logger.new(STDOUT).tap do |logger|
    logger.level = Logger::DEBUG
  end
end

#on_event_processor_errorObject

A Proc to be executed on an event processor error. App specific custom logic can be provided. i.e. report to an error reporting service like Rollbar.

Returns:

  • Proc



20
21
22
# File 'lib/event_sourcery/config.rb', line 20

def on_event_processor_error
  @on_event_processor_error
end

#on_unknown_eventObject

The default Proc to be run when an aggregate loads an event type that it doesn’t know how to handle. What’s specified here can be overridden when instantiating an aggregate instance. AggregateRoot#initialize

If no custom Proc is set, by default behaviour is to raise AggregateRoot::UnknownEventError

Returns:

  • Proc



13
14
15
# File 'lib/event_sourcery/config.rb', line 13

def on_unknown_event
  @on_unknown_event
end

#subscription_batch_sizeObject

Returns Integer.

Returns:

  • Integer



33
34
35
# File 'lib/event_sourcery/config.rb', line 33

def subscription_batch_size
  @subscription_batch_size
end