A lightweight micro-service message bus based on top of Sidekiq.
Inspired by the blog post SIDEKIQ AS A MICROSERVICE MESSAGE QUEUE by Brandon Hilkert
Add this line to your application's Gemfile:
gem 'voom-message_bus'
And then execute:
$ bundle
Or install it yourself as:
$ gem install voom-message_bus
Assuming you have a single app
and service
that you want to send messages back and forth between.
Add a worker to process messages from the service on the service message bus queue.
class ServiceWorker < Voom::Workers::EventProcessor
sidekiq_options queue: :service-message-bus
end
Add an initializer for publishing message to the service
Voom::MessageBus.configure do |config|
config.source = :app
config.channels << { name: 'app',
queue: 'app-message-bus',
worker: 'AppWorker',
exclude_envs: [:test]}
end
Startup sidekiq listening to the service queue
bundle exec sidekiq -q service-message-bus -q default
Add a worker to process messages from the service on the service message bus queue.
class AppWorker < Voom::Workers::EventProcessor
sidekiq_options queue: :app-message-bus
end
Add an initializer for publishing message to the service
Voom::MessageBus.configure do |config|
config.source = :service
config.channels << { name: 'service',
queue: 'service-message-bus',
worker: 'ServiceWorker',
exclude_envs: [:test]}
end
Startup sidekiq listening to the app queue
bundle exec sidekiq -q app-message-bus -q default
Voom::MessageBus::Publisher.publish(:app_hello_world, {data: 'Hello from App'})
Voom::MessageBus::Subscribe.subscribe(:service_hello_world) do |payload|
puts payload[:data]
end
Voom::MessageBus::Publisher.publish(:service_hello_world, {data: 'Hello from Service'})
Voom::MessageBus::Subscribe.subscribe(:app_hello_world) do |payload|
puts payload[:data]
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/rx/message_bus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Voom::MessageBus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.