Project

outboxer

0.0
The project is in a healthy, maintained state
Transactional outbox implementation for event driven Ruby on Rails applications that use SQL
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Outboxer

Gem Version Ruby

Background

Outboxer is an ActiveRecord implementation of the transactional outbox pattern for PostgreSQL and MySQL databases.

Setup

1. add gem to gemfile

gem 'outboxer'

2. install gem

bundle install

3. generate schema

bin/rails g outboxer:schema

4. migrate schema

bin/rake db:migrate

5. seed database

bin/rake outboxer:db:seed

6. generate publisher

sidekiq

bin/rails g outboxer:sidekiq_publisher

custom

bin/rails g outboxer:publisher

7. queue message after model creation

# your existing model

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

8. publish message out of band

Sidekiq

Outboxer::Publisher.publish do |message|
  case message[:messageable_type]
  when 'Event'
    EventCreatedJob.perform_async({ 'id' => message[:messageable_id] })
  end
end

Bunny

Outboxer::Publisher.publish do |message|
  case message[:messageable_type]
  when 'Event'
    queue.publish(JSON.generate({ 'id' => message[:messageable_id] }), persistent: true)
  end
end

Custom

Outboxer::Publisher.publish do |message|
  case message[:messageable_type]
  when 'Event'
    # publish message here

    logger.info "Outboxer published message #{message[:id]} for "\
      "#{message[:messageable_type]}::#{message[:messageable_id]}"
  end
end

9. run publisher

bin/outboxer_publisher

10. open rails console

bin/rails c

11. create event

Event.create!

12. Observe published message

Confirm the message has been published out of band

Management

Outboxer provides a sidekiq like UI to help manage your messages

Publishers

Screenshot 2024-11-23 at 5 47 14 pm

Messages

Screenshot 2024-11-17 at 2 47 34 pm

rails

config/routes.rb

require 'outboxer/web'

Rails.application.routes.draw do
  mount Outboxer::Web, at: '/outboxer'
end

rack

config.ru

require 'outboxer/web'

map '/outboxer' do
  run Outboxer::Web
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fast-programmer/outboxer.

License

This gem is available as open source under the terms of the GNU Lesser General Public License v3.0.