euston-daemons 1.0.2-java → 1.0.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/euston-daemons.gemspec +4 -3
- data/lib/euston-daemons/command_processor_daemon/config/environment.rb +8 -0
- data/lib/euston-daemons/command_processor_daemon/lib/components/command_handler_component.rb +32 -31
- data/lib/euston-daemons/command_processor_daemon/lib/daemon.rb +3 -3
- data/lib/euston-daemons/command_processor_daemon/lib/settings.rb +3 -0
- data/lib/euston-daemons/command_processor_daemon/rake_task.rb +7 -4
- data/lib/euston-daemons/event_processor_daemon/config/environment.rb +6 -4
- data/lib/euston-daemons/event_processor_daemon/lib/components/event_handler_component.rb +30 -44
- data/lib/euston-daemons/event_processor_daemon/lib/daemon.rb +2 -3
- data/lib/euston-daemons/event_processor_daemon/lib/settings.rb +4 -0
- data/lib/euston-daemons/framework/channel_thread.rb +22 -0
- data/lib/euston-daemons/framework/handler_bindings_component.rb +56 -0
- data/lib/euston-daemons/message_buffer_daemon/config/environment.rb +3 -5
- data/lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb +1 -2
- data/lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb +2 -1
- data/lib/euston-daemons/message_buffer_daemon/lib/daemon.rb +1 -1
- data/lib/euston-daemons/message_buffer_daemon/lib/publisher.rb +1 -1
- data/lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb +2 -2
- data/lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb +1 -1
- data/lib/euston-daemons/rake_tasks.rb +7 -0
- data/lib/euston-daemons/version.rb +1 -1
- data/lib/euston-daemons.rb +0 -6
- metadata +33 -32
- data/lib/euston-daemons/message_buffer_daemon/lib/mongodbs.rb +0 -5
- data/lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb +0 -56
data/euston-daemons.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'euston-daemons'
|
3
|
-
s.version = '1.0.
|
3
|
+
s.version = '1.0.3'
|
4
4
|
s.platform = RUBY_PLATFORM.to_s == 'java' ? 'java' : Gem::Platform::RUBY
|
5
5
|
s.authors = ['Lee Henson', 'Guy Boertje']
|
6
6
|
s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
|
@@ -26,22 +26,23 @@ Gem::Specification.new do |s|
|
|
26
26
|
lib/euston-daemons/event_processor_daemon/lib/settings.rb
|
27
27
|
lib/euston-daemons/event_processor_daemon/rake_task.rb
|
28
28
|
lib/euston-daemons/framework/basic_component.rb
|
29
|
+
lib/euston-daemons/framework/channel_thread.rb
|
29
30
|
lib/euston-daemons/framework/component_shutdown.rb
|
30
31
|
lib/euston-daemons/framework/daemon.rb
|
32
|
+
lib/euston-daemons/framework/handler_bindings_component.rb
|
31
33
|
lib/euston-daemons/framework/queue.rb
|
32
34
|
lib/euston-daemons/message_buffer_daemon/config/environment.rb
|
33
35
|
lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb
|
34
36
|
lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb
|
35
37
|
lib/euston-daemons/message_buffer_daemon/lib/daemon.rb
|
36
38
|
lib/euston-daemons/message_buffer_daemon/lib/message_logger.rb
|
37
|
-
lib/euston-daemons/message_buffer_daemon/lib/mongodbs.rb
|
38
39
|
lib/euston-daemons/message_buffer_daemon/lib/publisher.rb
|
39
|
-
lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb
|
40
40
|
lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb
|
41
41
|
lib/euston-daemons/message_buffer_daemon/lib/settings.rb
|
42
42
|
lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb
|
43
43
|
lib/euston-daemons/message_buffer_daemon/rake_task.rb
|
44
44
|
lib/euston-daemons/rake_task.rb
|
45
|
+
lib/euston-daemons/rake_tasks.rb
|
45
46
|
lib/euston-daemons/version.rb
|
46
47
|
]
|
47
48
|
# = MANIFEST =
|
@@ -8,6 +8,14 @@ Safely::Strategy::Log.logger = EUSTON_LOG
|
|
8
8
|
AMQP.settings.merge! ErbYaml.read(AMQP_CONFIG_PATH, EUSTON_ENV)
|
9
9
|
Euston::CommandProcessorDaemon::Settings.configure ErbYaml.read(DAEMON_CONFIG_PATH, EUSTON_ENV)
|
10
10
|
|
11
|
+
hash = ErbYaml.read(MONGOID_CONFIG_PATH, EUSTON_ENV)
|
12
|
+
|
13
|
+
event_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
|
14
|
+
read_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
|
15
|
+
|
16
|
+
Euston::RabbitMq.event_store_mongodb = Mongo::DB.new(hash[:event_store_database], event_connection)
|
17
|
+
Euston::RabbitMq.read_model_mongodb = Mongo::DB.new(hash[:read_model_database], read_connection)
|
18
|
+
|
11
19
|
Euston::EventStore::Persistence::Mongodb::Config.instance.logger = EUSTON_LOG
|
12
20
|
Euston::EventStore::Persistence::Mongodb::Config.instance.database = Euston::CommandProcessorDaemon::Settings.mongo_db_name
|
13
21
|
|
data/lib/euston-daemons/command_processor_daemon/lib/components/command_handler_component.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
1
|
module Euston
|
2
2
|
module CommandProcessorDaemon
|
3
3
|
class CommandHandlerComponent
|
4
|
-
|
4
|
+
include Euston::Daemons::ComponentShutdown
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
attr_reader :cli_thread
|
7
|
+
|
8
|
+
def initialize daemon
|
9
|
+
@daemon = daemon
|
8
10
|
end
|
9
11
|
|
10
12
|
def start
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
13
|
+
handler_finder = Euston::RabbitMq::HandlerFinder.new [Euston::CommandHandler]
|
14
|
+
handler_finder.namespaces << Euston::RabbitMq::CommandHandlers
|
15
|
+
handler_finder.namespaces.push(*COMMAND_HANDLER_NAMESPACES) if Object.const_defined? 'COMMAND_HANDLER_NAMESPACES'
|
16
|
+
handlers = handler_finder.find
|
17
|
+
|
18
|
+
binder = Euston::RabbitMq::CommandHandlerBinder.new handlers
|
19
|
+
binder.ensure_bindings_exist
|
20
|
+
|
21
|
+
@cli_thread = Thread.new(@daemon, handlers) do |daemon, handlers|
|
22
|
+
channel_thread = Euston::Daemons::ChannelThread.new
|
23
|
+
channel_thread.daemon = daemon
|
24
|
+
|
25
|
+
channel_thread.run do |channel|
|
26
|
+
message_received = Proc.new do |message|
|
27
|
+
command_headers = CommandHeaders.from_hash(message[:headers]).freeze
|
28
|
+
command_body = message[:body].freeze
|
29
|
+
|
30
|
+
handler_type = command_headers.type.to_s.camelize.to_sym
|
31
|
+
handler_method_name = "__version__#{command_headers.version}"
|
32
|
+
|
33
|
+
handlers.find_all { |reference| reference.name == handler_type }.each do |reference|
|
34
|
+
EUSTON_LOG.debug "Delivering message to: #{reference.name}.#{handler_method_name}"
|
35
|
+
|
36
|
+
reference.handler.new.send handler_method_name, command_headers, command_body
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Safely.report! e
|
40
|
+
Euston::RabbitMq::RetriableSubscription.new(channel, :command_handlers)
|
41
|
+
.when(:message_received => message_received)
|
42
|
+
.attach_queue_hook_listeners
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -48,7 +50,6 @@ module Euston
|
|
48
50
|
|
49
51
|
def stop
|
50
52
|
@cli_thread[:stop] = true
|
51
|
-
@rmq_client.disconnect
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -3,7 +3,7 @@ module Euston
|
|
3
3
|
class Daemon
|
4
4
|
include Euston::Daemon
|
5
5
|
|
6
|
-
attr_reader :clients
|
6
|
+
attr_reader :clients, :queue #,:ctx
|
7
7
|
|
8
8
|
def initialize #(ctx)
|
9
9
|
@queue = Queue.new
|
@@ -11,7 +11,7 @@ module Euston
|
|
11
11
|
@clients = {}
|
12
12
|
|
13
13
|
Settings.client_instances.times do |i|
|
14
|
-
@clients["command_component_#{i.succ}"] = CommandHandlerComponent.new
|
14
|
+
@clients["command_component_#{i.succ}"] = CommandHandlerComponent.new self
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -25,7 +25,7 @@ module Euston
|
|
25
25
|
EUSTON_LOG.debug "Components started"
|
26
26
|
|
27
27
|
@clients.each do |name, component|
|
28
|
-
EUSTON_LOG.debug("Thread state of #{name}: #{component.thread_state
|
28
|
+
EUSTON_LOG.debug("Thread state of #{name}: #{component.thread_state}")
|
29
29
|
end
|
30
30
|
|
31
31
|
@queue.pop #<-------- stops here until interrupted
|
@@ -5,12 +5,15 @@ module Euston
|
|
5
5
|
@config ||= {}
|
6
6
|
@config.merge!(cfg) if cfg && cfg.is_a?(Hash)
|
7
7
|
end
|
8
|
+
|
8
9
|
def self.client_instances
|
9
10
|
@config[:client_instances] || 1
|
10
11
|
end
|
12
|
+
|
11
13
|
def self.mongo_db_name
|
12
14
|
@config[:mongo_db_name]
|
13
15
|
end
|
16
|
+
|
14
17
|
def self.debug
|
15
18
|
@config[:debug]
|
16
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Euston
|
2
2
|
class CommandProcessorRakeTask < Euston::Daemons::RakeTask
|
3
|
-
attr_accessor :amqp_config_path, :command_handler_namespaces, :daemon_config_path
|
3
|
+
attr_accessor :amqp_config_path, :command_handler_namespaces, :daemon_config_path, :mongoid_config_path
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@command_handler_namespaces = []
|
@@ -16,11 +16,14 @@ module Euston
|
|
16
16
|
EUSTON_LOG.debug "AMQP config path: #{@amqp_config_path}"
|
17
17
|
Object.const_set :AMQP_CONFIG_PATH, @amqp_config_path
|
18
18
|
|
19
|
+
EUSTON_LOG.debug "Command handler namespaces: #{@command_handler_namespaces}"
|
20
|
+
Object.const_set :COMMAND_HANDLER_NAMESPACES, @command_handler_namespaces
|
21
|
+
|
19
22
|
EUSTON_LOG.debug "Daemon config path: #{@daemon_config_path}"
|
20
23
|
Object.const_set :DAEMON_CONFIG_PATH, @daemon_config_path
|
21
24
|
|
22
|
-
EUSTON_LOG.debug "
|
23
|
-
Object.const_set :
|
25
|
+
EUSTON_LOG.debug "Mongoid config path: #{@mongoid_config_path}"
|
26
|
+
Object.const_set :MONGOID_CONFIG_PATH, @mongoid_config_path
|
24
27
|
end
|
25
28
|
|
26
29
|
def load_environment
|
@@ -28,4 +31,4 @@ module Euston
|
|
28
31
|
require_rel 'config/environment.rb'
|
29
32
|
end
|
30
33
|
end
|
31
|
-
end
|
34
|
+
end
|
@@ -11,13 +11,15 @@ Euston::EventProcessorDaemon::Settings.configure ErbYaml.read(DAEMON_CONFIG_PATH
|
|
11
11
|
|
12
12
|
hash = ErbYaml.read(MONGOID_CONFIG_PATH, EUSTON_ENV)
|
13
13
|
|
14
|
-
|
14
|
+
event_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
|
15
|
+
read_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
|
16
|
+
|
17
|
+
Euston::RabbitMq.event_store_mongodb = Mongo::DB.new(hash[:event_store_database], event_connection)
|
18
|
+
Euston::RabbitMq.read_model_mongodb = Mongo::DB.new(hash[:read_model_database], read_connection)
|
15
19
|
|
16
20
|
Mongoid.configure do |config|
|
17
|
-
config.master =
|
21
|
+
config.master = Euston::RabbitMq.read_model_mongodb
|
18
22
|
config.logger = EUSTON_LOG
|
19
23
|
end
|
20
24
|
|
21
|
-
Euston::RabbitMq.read_model_mongodb = Mongo::DB.new(hash[:read_model_database], read_connection)
|
22
|
-
|
23
25
|
I18n.load_path += Dir[I18N_LOCALES_PATH]
|
@@ -3,69 +3,55 @@ module Euston
|
|
3
3
|
class EventHandlerComponent
|
4
4
|
include Euston::Daemons::ComponentShutdown
|
5
5
|
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :cli_threads
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
@
|
10
|
-
@
|
11
|
-
|
8
|
+
def initialize daemon
|
9
|
+
@daemon = daemon
|
10
|
+
@cli_threads = {}
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def start
|
14
|
+
handler_finder = Euston::RabbitMq::HandlerFinder.new [Euston::EventHandler]
|
15
|
+
handler_finder.namespaces << Euston::RabbitMq::EventHandlers
|
16
|
+
handler_finder.namespaces.push(*EVENT_HANDLER_NAMESPACES) if Object.const_defined? 'EVENT_HANDLER_NAMESPACES'
|
17
|
+
handlers = handler_finder.find
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
ns = ns.const_get c.to_sym
|
21
|
-
elsif found
|
22
|
-
EUSTON_LOG.warn "Couldn't find requested event handler namespace: #{handler_namespace}"
|
23
|
-
found = false
|
24
|
-
end
|
25
|
-
end
|
19
|
+
binder = Euston::RabbitMq::EventHandlerBinder.new handlers
|
20
|
+
binder.ensure_bindings_exist
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
22
|
+
handlers.each do |reference|
|
23
|
+
@cli_threads[reference.handler.to_s] = Thread.new(@daemon, reference) do |daemon, reference|
|
24
|
+
channel_thread = Euston::Daemons::ChannelThread.new
|
25
|
+
channel_thread.daemon = daemon
|
33
26
|
|
34
|
-
|
35
|
-
|
27
|
+
channel_thread.run do |channel|
|
28
|
+
message_received = Proc.new do |message|
|
29
|
+
event_headers = EventHeaders.from_hash message[:headers]
|
30
|
+
event_body = message[:body]
|
36
31
|
|
37
|
-
|
38
|
-
|
32
|
+
handler_method_name = "__event_handler__#{event_headers.type}__#{event_headers.version}"
|
33
|
+
|
34
|
+
EUSTON_LOG.debug "Delivering message to: #{reference.handler}.#{handler_method_name}"
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
binding.bind
|
47
|
-
binding.listen
|
48
|
-
rescue => e
|
49
|
-
Thread.current[:exception] = e
|
50
|
-
ensure
|
51
|
-
chan.disconnect
|
36
|
+
reference.handler.new.send handler_method_name, event_headers.freeze, event_body.freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
Euston::RabbitMq::RetriableSubscription.new(channel, reference.name.to_s.underscore)
|
40
|
+
.when(:message_received => message_received)
|
41
|
+
.attach_queue_hook_listeners
|
52
42
|
end
|
53
|
-
check_exception_and_shutdown
|
54
43
|
end
|
55
44
|
end
|
56
45
|
end
|
57
46
|
|
58
47
|
def thread_state
|
59
48
|
out = {}
|
60
|
-
@cli_threads.each
|
61
|
-
out[k] = th.status
|
62
|
-
end
|
49
|
+
@cli_threads.each { |k, th| out[k] = th.status }
|
63
50
|
out.inspect
|
64
51
|
end
|
65
52
|
|
66
53
|
def stop
|
67
54
|
@cli_threads.values.each { |th| th[:stop] = true }
|
68
|
-
@channel.disconnect
|
69
55
|
end
|
70
56
|
end
|
71
57
|
end
|
@@ -25,7 +25,7 @@ module Euston
|
|
25
25
|
# end
|
26
26
|
|
27
27
|
@queue = Queue.new
|
28
|
-
@event_handler = EventHandlerComponent.new
|
28
|
+
@event_handler = EventHandlerComponent.new self
|
29
29
|
end
|
30
30
|
|
31
31
|
def run
|
@@ -37,14 +37,13 @@ module Euston
|
|
37
37
|
# ele.daemon = self
|
38
38
|
# ele.start
|
39
39
|
# end
|
40
|
-
@event_handler.daemon = self
|
41
40
|
|
42
41
|
name = 'event_handler'
|
43
42
|
EUSTON_LOG.debug "Starting component: #{name}"
|
44
43
|
@event_handler.start
|
45
44
|
|
46
45
|
EUSTON_LOG.debug "Components started"
|
47
|
-
EUSTON_LOG.debug "Thread state of #{name}: #{@event_handler.thread_state
|
46
|
+
EUSTON_LOG.debug "Thread state of #{name}: #{@event_handler.thread_state}"
|
48
47
|
|
49
48
|
# EUSTON_LOG.debug @bus.thread_state.inspect
|
50
49
|
|
@@ -5,15 +5,19 @@ module Euston
|
|
5
5
|
@config ||= {}
|
6
6
|
@config.merge!(cfg) if cfg && cfg.is_a?(Hash)
|
7
7
|
end
|
8
|
+
|
8
9
|
def self.server_instances
|
9
10
|
@config[:server_instances] || 2
|
10
11
|
end
|
12
|
+
|
11
13
|
def self.bus_port_base
|
12
14
|
(@config[:zmq_base_port] || 8200).to_i
|
13
15
|
end
|
16
|
+
|
14
17
|
def self.mongo_db_name
|
15
18
|
@config[:mongo_db_name]
|
16
19
|
end
|
20
|
+
|
17
21
|
def self.debug
|
18
22
|
@config[:debug]
|
19
23
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Euston
|
2
|
+
module Daemons
|
3
|
+
class ChannelThread
|
4
|
+
include ComponentShutdown
|
5
|
+
|
6
|
+
def run &blk
|
7
|
+
begin
|
8
|
+
channel = AMQP::Channel.new
|
9
|
+
channel.prefetch(1)
|
10
|
+
|
11
|
+
yield channel
|
12
|
+
rescue => e
|
13
|
+
Thread.current[:exception] = e
|
14
|
+
ensure
|
15
|
+
channel.disconnect unless channel.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
check_exception_and_shutdown
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# module Euston
|
2
|
+
# module Daemons
|
3
|
+
# class HandlerBindingsComponent
|
4
|
+
# include Euston::Daemons::ComponentShutdown
|
5
|
+
|
6
|
+
# attr_reader :cli_threads
|
7
|
+
|
8
|
+
# def initialize
|
9
|
+
# @cli_threads = {}
|
10
|
+
# end
|
11
|
+
|
12
|
+
# def start
|
13
|
+
# inspector = Euston::RabbitMq::HandlerInspector.new
|
14
|
+
# inspector.namespaces.push *handler_namespaces
|
15
|
+
# inspector.when(:handler_found => bind_thread_to_handler).start
|
16
|
+
# end
|
17
|
+
|
18
|
+
# def thread_state
|
19
|
+
# states = {}
|
20
|
+
# @cli_threads.each { |key, thread| out[key] = thread.status }
|
21
|
+
# states.inspect
|
22
|
+
# end
|
23
|
+
|
24
|
+
# def stop
|
25
|
+
# @cli_threads.values.each { |th| th[:stop] = true }
|
26
|
+
# end
|
27
|
+
|
28
|
+
# private
|
29
|
+
|
30
|
+
# def bind_thread_to_handler namespace, handler
|
31
|
+
# @cli_threads["#{namespace}.#{handler}"] = Thread.new(namespace, handler) do |namespace, handler|
|
32
|
+
# begin
|
33
|
+
# channel = AMQP::Channel.new
|
34
|
+
# channel.prefetch(1)
|
35
|
+
|
36
|
+
# EUSTON_LOG.debug "Listening on: #{namespace}.#{handler}"
|
37
|
+
|
38
|
+
# binding = HandlerBinding.new channel, namespace, handler, routing_key_prefix
|
39
|
+
# binding.bind
|
40
|
+
# binding.listen
|
41
|
+
# rescue => e
|
42
|
+
# Thread.current[:exception] = e
|
43
|
+
# ensure
|
44
|
+
# channel.disconnect
|
45
|
+
# end
|
46
|
+
|
47
|
+
# check_exception_and_shutdown
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
|
51
|
+
# def handler_namespaces
|
52
|
+
# # abstract
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
@@ -14,13 +14,11 @@ hash = ErbYaml.read(MONGOID_CONFIG_PATH, EUSTON_ENV)
|
|
14
14
|
event_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
|
15
15
|
read_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
Euston::RabbitMq.event_store_mongodb = Euston::MessageBufferDaemon.event_store_mongodb = Mongo::DB.new event_database, event_connection
|
20
|
-
Euston::RabbitMq.read_model_mongodb = Euston::MessageBufferDaemon.read_model_mongodb = Mongo::DB.new hash[:read_model_database], read_connection
|
17
|
+
Euston::RabbitMq.event_store_mongodb = Mongo::DB.new(hash[:event_store_database], event_connection)
|
18
|
+
Euston::RabbitMq.read_model_mongodb = Mongo::DB.new(hash[:read_model_database], read_connection)
|
21
19
|
|
22
20
|
Euston::EventStore::Persistence::Mongodb::Config.instance.logger = EUSTON_LOG
|
23
|
-
Euston::EventStore::Persistence::Mongodb::Config.instance.database =
|
21
|
+
Euston::EventStore::Persistence::Mongodb::Config.instance.database = hash[:event_store_database]
|
24
22
|
|
25
23
|
Euston::RabbitMq.event_store = Euston::EventStore::Persistence::Mongodb::MongoPersistenceFactory.build
|
26
24
|
Euston::RabbitMq.event_store.init
|
@@ -16,8 +16,9 @@ module Euston
|
|
16
16
|
|
17
17
|
def start
|
18
18
|
@cli_thread = Thread.new do
|
19
|
-
@event_buffer = Euston::
|
19
|
+
@event_buffer = Euston::RabbitMq::ReadModel::MessageBuffer.events
|
20
20
|
@event_store = Euston::RabbitMq.event_store
|
21
|
+
|
21
22
|
until Thread.current[:stop] do
|
22
23
|
begin
|
23
24
|
loop do
|
@@ -28,7 +28,7 @@ module Euston
|
|
28
28
|
end
|
29
29
|
|
30
30
|
@clients.each do |name, component|
|
31
|
-
EUSTON_LOG.debug("Thread state of #{name}: #{component.thread_state
|
31
|
+
EUSTON_LOG.debug("Thread state of #{name}: #{component.thread_state}")
|
32
32
|
end
|
33
33
|
|
34
34
|
EUSTON_LOG.debug "Components started"
|
@@ -14,7 +14,7 @@ module Euston
|
|
14
14
|
include Euston::RabbitMq::Exchanges
|
15
15
|
|
16
16
|
def initialize channel, exchange_name
|
17
|
-
@read_model = Euston::
|
17
|
+
@read_model = Euston::RabbitMq::ReadModel::MessageBuffer.send exchange_name
|
18
18
|
|
19
19
|
@channel = channel
|
20
20
|
@exchange = get_exchange @channel, exchange_name
|
@@ -4,7 +4,7 @@ module Euston
|
|
4
4
|
class MessageLog
|
5
5
|
class << self
|
6
6
|
def commands
|
7
|
-
self.new "command_log", Euston::RabbitMq.
|
7
|
+
self.new "command_log", Euston::RabbitMq.event_store_mongodb
|
8
8
|
end
|
9
9
|
|
10
10
|
def events
|
@@ -33,4 +33,4 @@ module Euston
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
@@ -16,7 +16,7 @@ module Euston
|
|
16
16
|
include Hollywood
|
17
17
|
|
18
18
|
def initialize channel, exchange_name
|
19
|
-
@read_model = Euston::
|
19
|
+
@read_model = Euston::RabbitMq::ReadModel::MessageBuffer.send exchange_name
|
20
20
|
|
21
21
|
@channel = channel
|
22
22
|
@channel.prefetch(1)
|
data/lib/euston-daemons.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'hollywood'
|
2
2
|
require 'logger'
|
3
|
-
require 'rake/tasklib'
|
4
3
|
require 'require_all'
|
5
4
|
|
6
5
|
if RUBY_PLATFORM.to_s == 'java'
|
@@ -9,9 +8,4 @@ if RUBY_PLATFORM.to_s == 'java'
|
|
9
8
|
Java::JavaUtil::UUID.randomUUID().toString()
|
10
9
|
end
|
11
10
|
end
|
12
|
-
|
13
|
-
require_rel 'euston-daemons/rake_task.rb'
|
14
|
-
require_rel 'euston-daemons/command_processor_daemon/rake_task.rb'
|
15
|
-
require_rel 'euston-daemons/event_processor_daemon/rake_task.rb'
|
16
|
-
require_rel 'euston-daemons/message_buffer_daemon/rake_task.rb'
|
17
11
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: euston-daemons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.3
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Lee Henson
|
@@ -10,161 +10,161 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-20 00:00:00.000000000 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activemodel
|
18
|
-
version_requirements: &
|
18
|
+
version_requirements: &2158 !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 3.0.0
|
23
23
|
none: false
|
24
|
-
requirement: *
|
24
|
+
requirement: *2158
|
25
25
|
prerelease: false
|
26
26
|
type: :runtime
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
|
-
version_requirements: &
|
29
|
+
version_requirements: &2176 !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.0.0
|
34
34
|
none: false
|
35
|
-
requirement: *
|
35
|
+
requirement: *2176
|
36
36
|
prerelease: false
|
37
37
|
type: :runtime
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: erb-yaml
|
40
|
-
version_requirements: &
|
40
|
+
version_requirements: &2192 !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: 1.0.0
|
45
45
|
none: false
|
46
|
-
requirement: *
|
46
|
+
requirement: *2192
|
47
47
|
prerelease: false
|
48
48
|
type: :runtime
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: hollywood
|
51
|
-
version_requirements: &
|
51
|
+
version_requirements: &2208 !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 1.0.0
|
56
56
|
none: false
|
57
|
-
requirement: *
|
57
|
+
requirement: *2208
|
58
58
|
prerelease: false
|
59
59
|
type: :runtime
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: i18n
|
62
|
-
version_requirements: &
|
62
|
+
version_requirements: &2224 !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 0.5.0
|
67
67
|
none: false
|
68
|
-
requirement: *
|
68
|
+
requirement: *2224
|
69
69
|
prerelease: false
|
70
70
|
type: :runtime
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: require_all
|
73
|
-
version_requirements: &
|
73
|
+
version_requirements: &2240 !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.2.0
|
78
78
|
none: false
|
79
|
-
requirement: *
|
79
|
+
requirement: *2240
|
80
80
|
prerelease: false
|
81
81
|
type: :runtime
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: safely
|
84
|
-
version_requirements: &
|
84
|
+
version_requirements: &2256 !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 0.3.0
|
89
89
|
none: false
|
90
|
-
requirement: *
|
90
|
+
requirement: *2256
|
91
91
|
prerelease: false
|
92
92
|
type: :runtime
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: euston-rabbitmq
|
95
|
-
version_requirements: &
|
95
|
+
version_requirements: &2272 !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: 1.0.0
|
100
100
|
none: false
|
101
|
-
requirement: *
|
101
|
+
requirement: *2272
|
102
102
|
prerelease: false
|
103
103
|
type: :runtime
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: jessica
|
106
|
-
version_requirements: &
|
106
|
+
version_requirements: &2288 !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.0.0
|
111
111
|
none: false
|
112
|
-
requirement: *
|
112
|
+
requirement: *2288
|
113
113
|
prerelease: false
|
114
114
|
type: :runtime
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: jmongo
|
117
|
-
version_requirements: &
|
117
|
+
version_requirements: &2304 !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
119
|
- - ~>
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: 1.0.0
|
122
122
|
none: false
|
123
|
-
requirement: *
|
123
|
+
requirement: *2304
|
124
124
|
prerelease: false
|
125
125
|
type: :runtime
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: euston
|
128
|
-
version_requirements: &
|
128
|
+
version_requirements: &2320 !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: 1.0.0
|
133
133
|
none: false
|
134
|
-
requirement: *
|
134
|
+
requirement: *2320
|
135
135
|
prerelease: false
|
136
136
|
type: :runtime
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
name: euston-eventstore
|
139
|
-
version_requirements: &
|
139
|
+
version_requirements: &2336 !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
141
|
- - ~>
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: 1.0.0
|
144
144
|
none: false
|
145
|
-
requirement: *
|
145
|
+
requirement: *2336
|
146
146
|
prerelease: false
|
147
147
|
type: :runtime
|
148
148
|
- !ruby/object:Gem::Dependency
|
149
149
|
name: mongoid-glue
|
150
|
-
version_requirements: &
|
150
|
+
version_requirements: &2352 !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
152
|
- - ~>
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: 1.0.0
|
155
155
|
none: false
|
156
|
-
requirement: *
|
156
|
+
requirement: *2352
|
157
157
|
prerelease: false
|
158
158
|
type: :runtime
|
159
159
|
- !ruby/object:Gem::Dependency
|
160
160
|
name: rspec
|
161
|
-
version_requirements: &
|
161
|
+
version_requirements: &2368 !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
163
|
- - ~>
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: 2.6.0
|
166
166
|
none: false
|
167
|
-
requirement: *
|
167
|
+
requirement: *2368
|
168
168
|
prerelease: false
|
169
169
|
type: :development
|
170
170
|
description: ''
|
@@ -191,22 +191,23 @@ files:
|
|
191
191
|
- lib/euston-daemons/event_processor_daemon/lib/settings.rb
|
192
192
|
- lib/euston-daemons/event_processor_daemon/rake_task.rb
|
193
193
|
- lib/euston-daemons/framework/basic_component.rb
|
194
|
+
- lib/euston-daemons/framework/channel_thread.rb
|
194
195
|
- lib/euston-daemons/framework/component_shutdown.rb
|
195
196
|
- lib/euston-daemons/framework/daemon.rb
|
197
|
+
- lib/euston-daemons/framework/handler_bindings_component.rb
|
196
198
|
- lib/euston-daemons/framework/queue.rb
|
197
199
|
- lib/euston-daemons/message_buffer_daemon/config/environment.rb
|
198
200
|
- lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb
|
199
201
|
- lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb
|
200
202
|
- lib/euston-daemons/message_buffer_daemon/lib/daemon.rb
|
201
203
|
- lib/euston-daemons/message_buffer_daemon/lib/message_logger.rb
|
202
|
-
- lib/euston-daemons/message_buffer_daemon/lib/mongodbs.rb
|
203
204
|
- lib/euston-daemons/message_buffer_daemon/lib/publisher.rb
|
204
|
-
- lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb
|
205
205
|
- lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb
|
206
206
|
- lib/euston-daemons/message_buffer_daemon/lib/settings.rb
|
207
207
|
- lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb
|
208
208
|
- lib/euston-daemons/message_buffer_daemon/rake_task.rb
|
209
209
|
- lib/euston-daemons/rake_task.rb
|
210
|
+
- lib/euston-daemons/rake_tasks.rb
|
210
211
|
- lib/euston-daemons/version.rb
|
211
212
|
has_rdoc: true
|
212
213
|
homepage: http://github.com/leemhenson/euston-daemons
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require_rel '../mongodbs.rb'
|
2
|
-
|
3
|
-
module Euston
|
4
|
-
module MessageBufferDaemon
|
5
|
-
module ReadModel
|
6
|
-
class MessageBuffer
|
7
|
-
class << self
|
8
|
-
def commands
|
9
|
-
self.new "buffered_commands", Euston::MessageBufferDaemon.read_model_mongodb
|
10
|
-
end
|
11
|
-
|
12
|
-
def events
|
13
|
-
self.new "buffered_events", Euston::MessageBufferDaemon.event_store_mongod
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize name, mongodb
|
18
|
-
mongodb.create_collection name unless mongodb.collection_names.include? name
|
19
|
-
|
20
|
-
@collection = mongodb.collection name
|
21
|
-
@collection.ensure_index [ ['next_attempt', Mongo::ASCENDING] ], :unique => false, :name => "#{name}_next_attempt_index"
|
22
|
-
end
|
23
|
-
|
24
|
-
def buffer_new_message message
|
25
|
-
@collection.save({ 'doc_id' => message[:headers][:id],
|
26
|
-
'type' => message[:headers][:type],
|
27
|
-
'next_attempt' => (Time.now.to_f - 1.0),
|
28
|
-
'json' => ActiveSupport::JSON.encode(message) }, :safe => { :fsync => true })
|
29
|
-
end
|
30
|
-
|
31
|
-
def find_next_message
|
32
|
-
query = { 'next_attempt' => { '$lte' => Time.now.to_f } }
|
33
|
-
@collection.find_one(query)
|
34
|
-
end
|
35
|
-
|
36
|
-
def find_due_messages
|
37
|
-
query = { 'next_attempt' => { '$lte' => Time.now.to_f }}
|
38
|
-
@collection.find(query)
|
39
|
-
end
|
40
|
-
|
41
|
-
def get_by_id id
|
42
|
-
@collection.find_one({ 'doc_id' => id }) #doc or nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def set_next_attempt message
|
46
|
-
@collection.update({ 'doc_id' => message['doc_id'] },
|
47
|
-
{ '$set' => { 'next_attempt' => Time.now.to_f + 10 } }, :safe => { :fsync => true })
|
48
|
-
end
|
49
|
-
|
50
|
-
def remove_published_message id
|
51
|
-
@collection.remove({ 'doc_id' => id }, :safe => { :fsync => true })
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|