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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/event_sourcery/config.rb', line 44

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.
  }
  @on_event_processor_critical_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



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

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.



78
79
80
81
82
83
# File 'lib/event_sourcery/config.rb', line 78

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.



71
72
73
# File 'lib/event_sourcery/config.rb', line 71

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



31
32
33
# File 'lib/event_sourcery/config.rb', line 31

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::INFO



62
63
64
65
66
# File 'lib/event_sourcery/config.rb', line 62

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

#on_event_processor_critical_errorObject

A Proc to be executed on an event processor critical error. App defined behaviour can be provided. This will be called if an exception causes an a event processor to die. i.e. report to an error reporting service like Rollbar.

Returns:

  • Proc



28
29
30
# File 'lib/event_sourcery/config.rb', line 28

def on_event_processor_critical_error
  @on_event_processor_critical_error
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



41
42
43
# File 'lib/event_sourcery/config.rb', line 41

def subscription_batch_size
  @subscription_batch_size
end