Module: TCB
- Defined in:
- lib/tcb.rb,
lib/tcb/domain.rb,
lib/tcb/record.rb,
lib/tcb/publish.rb,
lib/tcb/version.rb,
lib/tcb/envelope.rb,
lib/tcb/event_bus.rb,
lib/tcb/stream_id.rb,
lib/tcb/command_bus.rb,
lib/tcb/event_query.rb,
lib/tcb/configuration.rb,
lib/tcb/rspec_helpers.rb,
lib/tcb/domain_context.rb,
lib/tcb/handles_events.rb,
lib/tcb/records_events.rb,
lib/tcb/handles_commands.rb,
lib/tcb/minitest_helpers.rb,
lib/tcb/correlation_query.rb,
lib/tcb/event_bus_shutdown.rb,
lib/tcb/test_helpers/shared.rb,
lib/tcb/event_store/in_memory.rb,
lib/tcb/event_bus_queue_pressure.rb,
lib/tcb/event_store/active_record.rb,
lib/tcb/event_bus/running_strategy.rb,
lib/tcb/event_bus/shutdown_strategy.rb,
lib/tcb/subscriber_invocation_failed.rb,
lib/tcb/event_bus/subscriber_registry.rb,
lib/tcb/subscriber_metadata_extractor.rb,
lib/tcb/event_bus/queue_pressure_monitor.rb,
lib/generators/tcb/domain/domain_generator.rb,
lib/generators/tcb/shared/command_argument.rb,
lib/generators/tcb/install/install_generator.rb,
lib/tcb/event_bus/termination_signal_handler.rb,
lib/generators/tcb/event_store/event_store_generator.rb
Defined Under Namespace
Modules: Domain, Generators, HandlesCommands, HandlesEvents, MinitestHelpers, RSpecHelpers, RecordsEvents, TestHelpers
Classes: Configuration, CorrelationQuery, DomainContext, Envelope, EventBus, EventBusQueuePressure, EventBusShutdown, EventQuery, EventStore, Record, StreamId, SubscriberInvocationFailed, SubscriberMetadataExtractor
Constant Summary
collapse
- VERSION =
"0.6.1"
- CommandHandlerNotFound =
Class.new(StandardError)
- ConfigurationError =
Class.new(StandardError)
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
74
75
76
|
# File 'lib/tcb.rb', line 74
def self.config
@config ||= Configuration.new
end
|
37
38
39
40
41
42
|
# File 'lib/tcb.rb', line 37
def self.configure(&block)
yield config
config.domain_modules = @domain_modules || []
config.permitted_serialization_classes
config.freeze
end
|
78
79
80
|
# File 'lib/tcb.rb', line 78
def self.configured?
!!@config && @config.event_bus_configured?
end
|
.dispatch(command, correlation_id: SecureRandom.uuid) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/tcb/command_bus.rb', line 5
def self.dispatch(command, correlation_id: SecureRandom.uuid)
validate!(command)
handler = resolve_handler(command)
Thread.current[:tcb_correlation_id] = correlation_id
handler.new.call(command)
correlation_id
ensure
Thread.current[:tcb_correlation_id] = nil
end
|
.domain_modules ⇒ Object
33
34
35
|
# File 'lib/tcb.rb', line 33
def self.domain_modules
@domain_modules || []
end
|
.domain_modules=(modules) ⇒ Object
29
30
31
|
# File 'lib/tcb.rb', line 29
def self.domain_modules=(modules)
@domain_modules = modules
end
|
.publish(*events_or_envelopes) ⇒ Object
2
3
4
5
6
7
8
|
# File 'lib/tcb/publish.rb', line 2
def self.publish(*events_or_envelopes)
events_or_envelopes.each do |e|
envelope = TCB::Envelope.coerce(e)
config.event_bus.publish(envelope)
end
events_or_envelopes
end
|
.read(domain_module) ⇒ Object
.read_correlation(correlation_id, across: nil) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/tcb.rb', line 62
def self.read_correlation(correlation_id, across: nil)
domains = across || config.domain_modules.select do |m|
m.respond_to?(:persist_registrations) && m.persist_registrations.any?
end
CorrelationQuery.new(
store: config.event_store,
correlation_id: correlation_id,
domains: domains
)
end
|
.record(events_from: [], events: [], within: nil, &block) ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/tcb.rb', line 44
def self.record(events_from: [], events: [], within: nil, &block)
Record.call(
events_from: events_from,
events: events,
within: within,
store: config.event_store,
registrations: config.persist_registrations,
&block
)
end
|
.reset!(graceful_shutdown_time: nil) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/tcb.rb', line 82
def self.reset!(graceful_shutdown_time: nil)
if configured?
graceful_shutdown_time ?
@config.event_bus.shutdown(drain: true, timeout: graceful_shutdown_time) :
@config.event_bus.force_shutdown
end
@config = nil
end
|