Skip to content

fast-programmer/outboxer

Repository files navigation

📤 Outboxer

Gem Version Coverage Status Join our Discord

Outboxer is an implementation of the transactional outbox pattern for event driven Ruby on Rails applications.

Quickstart

1. Install gem

bundle add outboxer
bundle install

2. Generate schema migrations and tests

bundle exec rails g outboxer:install

3. Migrate database

bundle exec rails db:migrate

4. Generate event schema and model

bundle exec rails generate model Event type:string created_at:datetime --skip-timestamps
bundle exec rails db:migrate

5. Queue outboxer message when event created

# app/models/event.rb

class Event < ApplicationRecord
  after_create do |event|
    Outboxer::Message.queue(messageable: event)
  end
end

6. Derive event type

# app/models/accountify/invoice_raised_event.rb

module Accountify
  class InvoiceRaisedEvent < Event; end
end

7. Create derived event type

bundle exec rails c
ActiveRecord::Base.logger = Logger.new(STDOUT)

Accountify::InvoiceRaisedEvent.create!(created_at: Time.current)

8. Observe transactional consistency

TRANSACTION                (0.2ms)  BEGIN
Event Create               (0.4ms)  INSERT INTO "events" ...
Outboxer::Message Create   (0.3ms)  INSERT INTO "outboxer_messages" ...
TRANSACTION                (0.2ms)  COMMIT

9. Publish event

# bin/outboxer_publisher

Outboxer::Publisher.publish_message do |publisher, message|
  # TODO: publish event here
end

To integrate with Active Cable, Sidekiq, Bunny, Kafka, AWS SQS and others, see the publisher integration guide.

Testing

To ensure you have end to end coverage:

bundle exec rspec spec/bin/outboxer_publisher

Monitoring

Monitor multithreaded publishers using Outboxer's built-in web UI:

Publishers

Screenshot 2025-04-30 at 6 25 06 pm

Messages

Screenshot 2025-04-30 at 6 25 37 pm

Rails

# config/routes.rb

require 'outboxer/web'

mount Outboxer::Web, at: '/outboxer'

Rack

# config.ru

require 'outboxer/web'

map '/outboxer' { run Outboxer::Web }

Contributing

All contributions are welcome!

License

Open-sourced under LGPL v3.0.

About

Transactional outbox for event driven Ruby on Rails apps backed by SQL

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages