Skip to content

Getting Started

Ahmad Elassuty edited this page Jan 27, 2021 · 2 revisions

πŸ’Ž Installation

Add this line to your application's Gemfile:

gem 'event_router'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install event_router

EventRouter is already pre-configured with some defaults. For more details about supported configurations and the defaults, please check Confirmations page


πŸ‘¨πŸ»β€πŸ’» Publish your first event

It is very easy to create a new domain event and deliver it to multiple destinations.

  • Define your new domain event class and setup one or more handlers using deliver_to method. At the execution time, the destination will receive your event.

    class OrderPlaced < EventRouter::Event
      deliver_to :email_notifier, handler: EmailNotifier
    end
  • Define your handler and add a class method with the same event class name underscored:

    class EmailNotifier
      def self.order_placed(event, payload)
        # [TODO] Handle the event here
      end
    end
  • Publish your event:

    OrderPlaced.publish(order_id: 1, time: Time.now)

That is it your are done! πŸŽ‰

Clone this wiki locally