Eventsimple
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
- Home - Installation, configuration, and getting started
- Usage-Events - How to create and use events
- Usage-Reactors - Handle side effects with sync and async reactors
- Encryption - Encrypt sensitive data in event messages
- Outbox-Pattern - Implement ordered event processing
- Best-Practices - Development guidelines and best practices
- Testing - Testing best practices for events and reactors
- Helper-Methods - Convenience methods for common tasks
- Data-Migrations - Migrating event data
- Existing-Models - Adding Eventsimple to existing models
- Factory-Bot-Compatibility - Using Factory Bot with Eventsimple