Skip to content

Commit

Permalink
Eventwired!
Browse files Browse the repository at this point in the history
(TODO: Review this commit for future improvements on Eventwire)
  • Loading branch information
cavalle committed Oct 16, 2011
1 parent c848114 commit c3b950d
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 242 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ gem 'rails', '3.0.0'
gem 'uuidtools'
gem 'ohm'

gem 'eventwire', :git => 'git://github.com/cavalle/eventwire.git'

gem 'em-redis', :require => false

gem 'bunny', :require => false
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: git://github.com/cavalle/eventwire.git
revision: 073cdf9e82f557779ea4e97c646ecae3b895df5a
specs:
eventwire (0.0.1)
json

GEM
remote: http://rubygems.org/
specs:
Expand Down Expand Up @@ -67,6 +74,7 @@ GEM
term-ansicolor (~> 1.0.5)
thor (>= 0.13.6)
i18n (0.4.2)
json (1.6.1)
json_pure (1.5.0)
launchy (0.3.7)
configuration (>= 0.0.5)
Expand Down Expand Up @@ -167,6 +175,7 @@ DEPENDENCIES
bunny
capybara
em-redis
eventwire!
ffi-rzmq
foreman
launchy
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: bundle exec thin start
bus: bundle exec rake event_bus:start
bus: bundle exec rake environment eventwire:work --trace
14 changes: 11 additions & 3 deletions config/initializers/infrastructure.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Rails.application.class.configure do
config.event_bus = 'EventBus::Redis'
config.event_subscribers = %w{ClientReport ClientDetailsReport AccountDetailsReport MoneyTransferSaga}
config.to_prepare { EventBus.init }
config.to_prepare do
# Initialize Eventwire before each request so that using the InProcess driver
# in development the event handlers are declared only once
Eventwire.driver = Rails.env.test? ? 'InProcess' : 'Redis'
Eventwire.on_error do |ex|
raise ex
end
ClientReport; ClientDetailsReport; AccountDetailsReport; MoneyTransferSaga
end
end


4 changes: 3 additions & 1 deletion lib/infrastructure/domain_repository.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module DomainRepository

class << self

include Eventwire::Publisher

def aggregates
Thread.current[:"DomainRepositoryCurrentStore"]
Expand Down Expand Up @@ -48,7 +50,7 @@ def save(event)
end

def publish(event)
EventBus.publish(event)
publish_event(event.name, {:data => event.data})
end

end
Expand Down
11 changes: 0 additions & 11 deletions lib/infrastructure/event_bus.rb

This file was deleted.

63 changes: 0 additions & 63 deletions lib/infrastructure/event_bus/amqp.rb

This file was deleted.

21 changes: 0 additions & 21 deletions lib/infrastructure/event_bus/in_process.rb

This file was deleted.

73 changes: 0 additions & 73 deletions lib/infrastructure/event_bus/redis.rb

This file was deleted.

51 changes: 0 additions & 51 deletions lib/infrastructure/event_bus/zero.rb

This file was deleted.

12 changes: 6 additions & 6 deletions lib/infrastructure/event_handler.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module EventHandler
include Eventwire::Subscriber::DSL

def on(*events, &block)
events.each do |event_name|
::EventBus.subscribe(event_name, "#{name}:#{increment_handlers_count}:#{event_name}", &block)
super(event_name) do |event|
event.data = event.data.to_hash.symbolize_keys
block.call(event)
end
end
end

def increment_handlers_count
@handlers_count ||= 0
@handlers_count += 1
end

end
5 changes: 1 addition & 4 deletions lib/tasks/event_bus.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
desc "Start Event Bus"
task "event_bus:start" => :environment do
EventBus.start
end
require 'eventwire/tasks'
11 changes: 4 additions & 7 deletions spec/acceptance/acceptance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@

config.before(:each) do
Ohm.flush
EventBus.purge
@t = Thread.new { EventBus.start }
@t.abort_on_exception = true
end

config.after(:each) do
EventBus.stop
@t.join(1)
@t.kill
Capybara.reset_sessions!
end
end

Eventwire.on_error do |ex|
raise ex
end

Capybara.app = Proc.new { |env|
EventBus.wait_for_events
Rails.application.call(env)
}

Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/support/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def execute_command(*args)
DomainRepository.begin
result = "#{args.shift}_command_handler".camelize.constantize.new.execute(*args)
DomainRepository.commit
EventBus.wait_for_events
result
end

Expand Down

0 comments on commit c3b950d

Please sign in to comment.