Outboxer is an ActiveRecord implementation of the transactional outbox pattern.
It was built to help Rails teams migrate to eventually consistent event driven architecture quickly, using existing tools and infrastructure.
gem 'outboxer'
bundle install
bin/rails g outboxer:schema
bin/rake db:migrate
class Event < ActiveRecord::Base
# ...
after_create do |event|
Outboxer::Message.backlog(messageable: event)
end
end
bin/rails g outboxer:message_publisher
Outboxer::Publisher.publish do |message|
case message[:messageable_type]
when 'Event'
EventCreatedJob.perform_async({ 'id' => message[:messageable_id] })
end
end
class EventCreatedJob
include Sidekiq::Job
def perform(args)
event = Event.find(args['id'])
# ...
end
end
bin/outboxer_message_publisher
manage backlogged, queued, publishing and failed messages with the web ui
require 'outboxer/web'
Rails.application.routes.draw do
mount Outboxer::Web, at: '/outboxer'
end
require 'outboxer/web'
map '/outboxer' do
run Outboxer::Web
end
understanding how much memory and cpu is required by the message publisher
run bin/outboxer_message_publishermon
Bug reports and pull requests are welcome on GitHub at https://github.com/fast-programmer/outboxer.
This gem is available as open source under the terms of the GNU Lesser General Public License v3.0.