Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Event Collaboration for the Rubyist

Event Collaboration for the Rubyist

Luismi Cavallé

December 29, 2011
Tweet

More Decks by Luismi Cavallé

Other Decks in Programming

Transcript

  1. Multiple components work together by communicating with each other by

    sending events when their internal state changes. — Martin Fowler http://tinyurl.com/eaaDev
  2. Given one task is pending When I complete it Then

    my boss is noti ed Given I completed one task in 1 day And I completed other task in 2 days When I see the performance report Then my performance is 1.5 tasks/day
  3. class Task def mark_as_completed! update_attributes! :completed => true notify_boss update_progress_report

    end def notify_boss # ... end def update_progress_report # ... end end
  4. The Single Responsibility Principle “An object should have only a

    single responsibility.” — Uncle Bob http://tinyurl.com/OOPrinciples
  5. The Open Closed Principle “[An object] should be open for

    extension, but closed for modi cation.” — Uncle Bob http://tinyurl.com/OOPrinciples
  6. module PerformanceStats on :task_created do |event| start_times[event.task_name] = Time.now end

    on :task_completed do |event| completion_time_sum += Time.now - start_times.delete(event.task_name) completion_time_count += 1 end def self.average_performance completion_time_sum / completion_time_count end # ... end
  7. Con guration Eventwire.configure do |config| config.adapter = :AMQP config.logger =

    Rails.logger config.middleware << MyCustomMiddleware end
  8. P1 P2 S1 S3 S2 S2 S2 Pub / Sub

    Bus Sub. Balancing Messaging Patterns
  9. Current status Not released to Rubygems yet Some adapters are

    very experimental Next milestone: Production at BeBanjo