Eventsimple

Github Actions Gem Version

What

Eventsimple implements a simple deterministic event driven system using ActiveRecord and ActiveJob

Use Eventsimple to:

  • Add Event Sourcing to your ActiveRecord models.
  • Pub/Sub.
  • Implement a transactional outbox.
  • Store audit logs.

Write events to update models

class UserComponent::Events::Created < UserEvent
  class Message < Eventsimple::Message
    attribute :name, Eventsimple::Types::String
    attribute :email, Eventsimple::Types::String
  end

  def can_apply?(user)
    user.new_record?
  end

  def apply(user)
    user.name = data.name
    user.email = data.email
  end
end

UserComponent::Events::Created.create!(
  user: User.new,
  data: { name: "John doe", email: "johndoe@example.com" }
)

Execute side effects using Reactors

class UserComponent::Dispatcher < Eventsimple::Dispatcher
  on(
    UserComponent::Events::Created, async: SendWelcomeEmail
  )
end

class UserComponent::Reactors::SendWelcomeEmail < Eventsimple::Reactor
  def call(event)
    EmailService.send_welcome_email(event.aggregate)
  end
end

Quick Start