euston-daemons 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. data/euston-daemons.gemspec +4 -3
  2. data/lib/euston-daemons/command_processor_daemon/config/environment.rb +8 -0
  3. data/lib/euston-daemons/command_processor_daemon/lib/components/command_handler_component.rb +32 -31
  4. data/lib/euston-daemons/command_processor_daemon/lib/daemon.rb +3 -3
  5. data/lib/euston-daemons/command_processor_daemon/lib/settings.rb +3 -0
  6. data/lib/euston-daemons/command_processor_daemon/rake_task.rb +7 -4
  7. data/lib/euston-daemons/event_processor_daemon/config/environment.rb +6 -4
  8. data/lib/euston-daemons/event_processor_daemon/lib/components/event_handler_component.rb +30 -44
  9. data/lib/euston-daemons/event_processor_daemon/lib/daemon.rb +2 -3
  10. data/lib/euston-daemons/event_processor_daemon/lib/settings.rb +4 -0
  11. data/lib/euston-daemons/framework/channel_thread.rb +22 -0
  12. data/lib/euston-daemons/framework/handler_bindings_component.rb +56 -0
  13. data/lib/euston-daemons/message_buffer_daemon/config/environment.rb +3 -5
  14. data/lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb +1 -2
  15. data/lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb +2 -1
  16. data/lib/euston-daemons/message_buffer_daemon/lib/daemon.rb +1 -1
  17. data/lib/euston-daemons/message_buffer_daemon/lib/publisher.rb +1 -1
  18. data/lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb +2 -2
  19. data/lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb +1 -1
  20. data/lib/euston-daemons/rake_tasks.rb +7 -0
  21. data/lib/euston-daemons/version.rb +1 -1
  22. data/lib/euston-daemons.rb +0 -6
  23. metadata +27 -26
  24. data/lib/euston-daemons/message_buffer_daemon/lib/mongodbs.rb +0 -5
  25. data/lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb +0 -56
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'euston-daemons'
3
- s.version = '1.0.2'
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
 
@@ -1,43 +1,45 @@
1
1
  module Euston
2
2
  module CommandProcessorDaemon
3
3
  class CommandHandlerComponent
4
- attr_reader :rmq_client, :cli_thread
4
+ include Euston::Daemons::ComponentShutdown
5
5
 
6
- def initialize
7
- @rmq_client = AMQP::Channel.new
6
+ attr_reader :cli_thread
7
+
8
+ def initialize daemon
9
+ @daemon = daemon
8
10
  end
9
11
 
10
12
  def start
11
- @cli_thread = Thread.new do
12
- begin
13
- command_handler_bindings = Euston::RabbitMq::CommandHandlerBindings.new(@rmq_client)
14
- command_handler_bindings.add_namespace Euston::RabbitMq::CommandHandlers
15
-
16
- if Object.const_defined? 'COMMAND_HANDLER_NAMESPACES'
17
- COMMAND_HANDLER_NAMESPACES.each do |handler_namespace|
18
- ns = Object
19
- found = true
20
-
21
- handler_namespace.split('::').each do |c|
22
- if found && ns.const_defined?(c)
23
- ns = ns.const_get c.to_sym
24
- elsif found
25
- EUSTON_LOG.warn "Couldn't find requested command handler namespace: #{handler_namespace}"
26
- found = false
27
- end
28
- end
29
-
30
- if found
31
- EUSTON_LOG.debug "Successfully found command handler namespace: #{handler_namespace}"
32
- command_handler_bindings.add_namespace ns
33
- end
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
- command_handler_bindings.finalize_bindings
38
- rescue => e
39
- Thread.current[:exception] = e
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,:queue #,:ctx
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.inspect}")
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 "Command handler namespaces: #{@command_handler_namespaces}"
23
- Object.const_set :COMMAND_HANDLER_NAMESPACES, @command_handler_namespaces
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
- read_connection = Mongo::Connection.new hash[:host], hash[:port], :safe => hash[:safe] #, :logger => EUSTON_LOG
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 = Mongo::DB.new(hash[:read_model_database], read_connection)
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 :channel, :cli_threads
6
+ attr_reader :cli_threads
7
7
 
8
- def initialize()
9
- @channel = AMQP::Channel.new
10
- @channel.prefetch(1)
11
- @event_handler_bindings = Euston::RabbitMq::EventHandlerBindings.new(@channel)
8
+ def initialize daemon
9
+ @daemon = daemon
10
+ @cli_threads = {}
11
+ end
12
12
 
13
- if Object.const_defined? 'EVENT_HANDLER_NAMESPACES'
14
- EVENT_HANDLER_NAMESPACES.each do |handler_namespace|
15
- ns = Object
16
- found = true
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
- handler_namespace.split('::').each do |c|
19
- if found && ns.const_defined?(c)
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
- if found
28
- EUSTON_LOG.debug "Successfully found event handler namespace: #{handler_namespace}"
29
- @event_handler_bindings.add_namespace ns
30
- end
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
- @cli_threads = {}
35
- end
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
- def start
38
- @event_handler_bindings.namespaced_handler_types.each do |namespace, handler_type|
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
- @cli_threads["#{namespace}.#{handler_type}"] = Thread.new(namespace, handler_type) do |ns, ht|
41
- begin
42
- chan = AMQP::Channel.new
43
- chan.prefetch(1)
44
- EUSTON_LOG.debug "EventHandlerBinding for: #{ns}.#{ht}"
45
- binding = Euston::RabbitMq::EventHandlerBinding.new(chan, ns, ht)
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 do |k, th|
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.inspect}"
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
- event_database = hash[:event_store_database]
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 = event_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
@@ -68,7 +68,6 @@ module Euston
68
68
  end
69
69
  end
70
70
  end
71
-
72
71
  end
73
72
  end
74
- end
73
+ end
@@ -16,8 +16,9 @@ module Euston
16
16
 
17
17
  def start
18
18
  @cli_thread = Thread.new do
19
- @event_buffer = Euston::MessageBufferDaemon::ReadModel::MessageBuffer.events
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.inspect}")
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::MessageBufferDaemon::ReadModel::MessageBuffer.send exchange_name
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.read_model_mongodb
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::MessageBufferDaemon::ReadModel::MessageBuffer.send exchange_name
19
+ @read_model = Euston::RabbitMq::ReadModel::MessageBuffer.send exchange_name
20
20
 
21
21
  @channel = channel
22
22
  @channel.prefetch(1)
@@ -0,0 +1,7 @@
1
+ require 'euston-daemons'
2
+ require 'rake/tasklib'
3
+
4
+ require_rel 'rake_task.rb'
5
+ require_rel 'command_processor_daemon/rake_task.rb'
6
+ require_rel 'event_processor_daemon/rake_task.rb'
7
+ require_rel 'message_buffer_daemon/rake_task.rb'
@@ -1,5 +1,5 @@
1
1
  module Euston
2
2
  module Daemons
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
@@ -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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euston-daemons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-18 00:00:00.000000000 Z
13
+ date: 2011-09-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &5232880 !ruby/object:Gem::Requirement
17
+ requirement: &81760130 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *5232880
25
+ version_requirements: *81760130
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &5823660 !ruby/object:Gem::Requirement
28
+ requirement: &81759760 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *5823660
36
+ version_requirements: *81759760
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: erb-yaml
39
- requirement: &5821580 !ruby/object:Gem::Requirement
39
+ requirement: &81759360 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *5821580
47
+ version_requirements: *81759360
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: hollywood
50
- requirement: &5798820 !ruby/object:Gem::Requirement
50
+ requirement: &81759040 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *5798820
58
+ version_requirements: *81759040
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: i18n
61
- requirement: &5787920 !ruby/object:Gem::Requirement
61
+ requirement: &81758510 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.5.0
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *5787920
69
+ version_requirements: *81758510
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: require_all
72
- requirement: &5784300 !ruby/object:Gem::Requirement
72
+ requirement: &81758000 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 1.2.0
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *5784300
80
+ version_requirements: *81758000
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: safely
83
- requirement: &5772460 !ruby/object:Gem::Requirement
83
+ requirement: &81757700 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 0.3.0
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *5772460
91
+ version_requirements: *81757700
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: euston
94
- requirement: &5770300 !ruby/object:Gem::Requirement
94
+ requirement: &81757290 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 1.0.0
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *5770300
102
+ version_requirements: *81757290
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: euston-eventstore
105
- requirement: &5768780 !ruby/object:Gem::Requirement
105
+ requirement: &81756890 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 1.0.0
111
111
  type: :runtime
112
112
  prerelease: false
113
- version_requirements: *5768780
113
+ version_requirements: *81756890
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: mongoid-glue
116
- requirement: &5767800 !ruby/object:Gem::Requirement
116
+ requirement: &81756440 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: 1.0.0
122
122
  type: :runtime
123
123
  prerelease: false
124
- version_requirements: *5767800
124
+ version_requirements: *81756440
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
- requirement: &5766760 !ruby/object:Gem::Requirement
127
+ requirement: &81756000 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
@@ -132,7 +132,7 @@ dependencies:
132
132
  version: 2.6.0
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *5766760
135
+ version_requirements: *81756000
136
136
  description: ''
137
137
  email:
138
138
  - lee.m.henson@gmail.com
@@ -157,22 +157,23 @@ files:
157
157
  - lib/euston-daemons/event_processor_daemon/lib/settings.rb
158
158
  - lib/euston-daemons/event_processor_daemon/rake_task.rb
159
159
  - lib/euston-daemons/framework/basic_component.rb
160
+ - lib/euston-daemons/framework/channel_thread.rb
160
161
  - lib/euston-daemons/framework/component_shutdown.rb
161
162
  - lib/euston-daemons/framework/daemon.rb
163
+ - lib/euston-daemons/framework/handler_bindings_component.rb
162
164
  - lib/euston-daemons/framework/queue.rb
163
165
  - lib/euston-daemons/message_buffer_daemon/config/environment.rb
164
166
  - lib/euston-daemons/message_buffer_daemon/lib/components/buffer_component.rb
165
167
  - lib/euston-daemons/message_buffer_daemon/lib/components/event_store_component.rb
166
168
  - lib/euston-daemons/message_buffer_daemon/lib/daemon.rb
167
169
  - lib/euston-daemons/message_buffer_daemon/lib/message_logger.rb
168
- - lib/euston-daemons/message_buffer_daemon/lib/mongodbs.rb
169
170
  - lib/euston-daemons/message_buffer_daemon/lib/publisher.rb
170
- - lib/euston-daemons/message_buffer_daemon/lib/read_model/message_buffer.rb
171
171
  - lib/euston-daemons/message_buffer_daemon/lib/read_model/message_log.rb
172
172
  - lib/euston-daemons/message_buffer_daemon/lib/settings.rb
173
173
  - lib/euston-daemons/message_buffer_daemon/lib/subscriber.rb
174
174
  - lib/euston-daemons/message_buffer_daemon/rake_task.rb
175
175
  - lib/euston-daemons/rake_task.rb
176
+ - lib/euston-daemons/rake_tasks.rb
176
177
  - lib/euston-daemons/version.rb
177
178
  homepage: http://github.com/leemhenson/euston-daemons
178
179
  licenses: []
@@ -1,5 +0,0 @@
1
- module Euston
2
- module MessageBufferDaemon
3
- mattr_accessor :event_store_mongodb, :read_model_mongodb
4
- end
5
- end
@@ -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