This gem provides tools for easy and painless two-sided communication between two rails applications
Add this line to your application's Gemfile:
gem 'communications', github: 'sck-v/communications'
And then execute:
$ bundle
The usage is simple:
- Configure receiver
Communications.configure do
handle :channel_name, with: SomeHandler
on_message_failure do |queue, payload, _|
Rails.logger.info 'Message processing error'
end
end
- Start the reciever
Communications::Receiver.start! rescue Bunny::TCPConnectionFailedForAllHosts
- Implement Handler class
require 'communications/handler'
class SomeHandler
include Communications::Handler
def handle(payload)
SomeWorker.do_something_with_payload(payload)
end
end
- Publish message
Communications::Publisher.publish(:channel_name, message_hash)