I am currently building an architechture with a rails process and multiple worker processes which need to be informed of certain events (like the creation of an object).
Rails
| API Worker
+----------o------o--------o------ - - -
Some other
daemon
I'd like to do the following
class Article
after_creation do
MessageBus.send type: "article-created", id: self.id
end
end
While the processes (API, Worker, Daemons, ...) just subscribe to the message bus and a block is called when a message comes in.
MessageBus.subscribe do |msg|
if msg['type'] == 'article-created'
# if this is my websocket daemon, I would push the article to the browser
# if this is my indexing daemon, I would reindex the full-text search
# if this is ... you get the deal.
end
end
Currently I am using a local unix domain socket where I push JSON in with UNIXSocket
and get it with EventMachine.start_unix_domain_server
. But that allows only two-way communication. I also thought about using resque, but this is more a message queue while I need a bus. And it depends on redis. I am quite sure there must be a gem, that implements some message bus in ruby, but googling did not lead to any result