Outboxer is an implementation of the transactional outbox pattern for Ruby on Rails applications.
It helps migrate your existing stack to event-driven architecture whilst avoiding the dual write problem.
1. Install gem
bundle add outboxer bundle install2. Generate schema migrations, publisher script and tests
bin/rails g outboxer:install3. Migrate database
bin/rails db:migrate4. Generate basic event schema and model
bin/rails generate model Event type:string created_at:datetime --skip-timestamps bin/rails db:migrate5. Queue message after event created
# app/models/event.rb class Event < ApplicationRecord after_create do |event| Outboxer::Message.queue(messageable: event) end end6. Publish messages
# bin/outboxer_publisher Outboxer::Publisher.publish_messages do |publisher, messages| messages.each do |message| # TODO: publish messages here # see https://github.com/fast-programmer/outboxer/wiki/Outboxer-publisher-block-examples Outboxer::Message.published_by_ids( ids: [message[:id]], publisher_id: publisher[:id], publisher_name: publisher[:name]) rescue StandardError => error Outboxer::Message.failed_by_ids( ids: [message[:id]], exception: error, publisher_id: publisher[:id], publisher_name: publisher[:name]) end endThe generated spec/bin/outboxer_publisher adds end to end queue and publish message test coverage.
Monitor using the built-in web UI:
Rails
# config/routes.rb require 'outboxer/web' mount Outboxer::Web, at: '/outboxer'Rack
# config.ru require 'outboxer/web' map '/outboxer' { run Outboxer::Web }All contributions are welcome!
Open-sourced under LGPL v3.0.