module MicroBunny
Attributes
channel[RW]
connection[RW]
settings[RW]
Public Class Methods
configure() { |settings| ... }
click to toggle source
# File lib/microbunny.rb, line 24 def configure self.settings ||= Settings.new yield(settings) end
event(name)
click to toggle source
# File lib/microbunny.rb, line 56 def event(name) EventTrigger.new(channel, name) end
start()
click to toggle source
# File lib/microbunny.rb, line 29 def start self.connection = Connection.new( adapter: RABBIT_MQ_ADAPTER, host: self.settings.host, vhost: self.settings.vhost, username: self.settings.username, password: self.settings.password ) self.channel = self.connection.channel end
stop()
click to toggle source
# File lib/microbunny.rb, line 41 def stop self.connection.stop end
subscribe(topics, record_ids = [])
click to toggle source
# File lib/microbunny.rb, line 45 def subscribe(topics, record_ids = []) raise_bad_start unless self.channel records = record_ids.map(&Record.method(:new)) subs = Subscriptions.new(self.channel, topics, records) do |payload| handle(payload) end subs.create end
Private Class Methods
handle(json)
click to toggle source
# File lib/microbunny.rb, line 62 def handle(json) payload = Payload.deserialize(json) consumer = EventLookup.new(payload.event).consumer.new if payload.record consumer.process(payload.message, payload.record) else consumer.process(payload.message) end end
raise_bad_start()
click to toggle source
# File lib/microbunny.rb, line 73 def raise_bad_start raise "Must call MicroBunny.start before you can subscribe" end