Class: BumpyBridge
- Inherits:
-
Object
- Object
- BumpyBridge
- Includes:
- Trickery::Config
- Defined in:
- lib/bumpy_bridge.rb,
lib/bumpy_bridge/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#bunny ⇒ Object
Returns the value of attribute bunny.
-
#bunny_channel ⇒ Object
Returns the value of attribute bunny_channel.
-
#config ⇒ Object
Returns the value of attribute config.
-
#faye ⇒ Object
Returns the value of attribute faye.
Instance Method Summary collapse
-
#initialize(file) ⇒ BumpyBridge
constructor
A new instance of BumpyBridge.
- #run ⇒ Object
Constructor Details
#initialize(file) ⇒ BumpyBridge
Returns a new instance of BumpyBridge.
21 22 23 |
# File 'lib/bumpy_bridge.rb', line 21 def initialize(file) self.config = read_config(file) end |
Instance Attribute Details
#bunny ⇒ Object
Returns the value of attribute bunny.
19 20 21 |
# File 'lib/bumpy_bridge.rb', line 19 def bunny @bunny end |
#bunny_channel ⇒ Object
Returns the value of attribute bunny_channel.
19 20 21 |
# File 'lib/bumpy_bridge.rb', line 19 def bunny_channel @bunny_channel end |
#config ⇒ Object
Returns the value of attribute config.
19 20 21 |
# File 'lib/bumpy_bridge.rb', line 19 def config @config end |
#faye ⇒ Object
Returns the value of attribute faye.
19 20 21 |
# File 'lib/bumpy_bridge.rb', line 19 def faye @faye end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bumpy_bridge.rb', line 25 def run # setup rabbitmq self.bunny = Bunny.new read_timeout: 10, heartbeat: 10 bunny.start self.bunny_channel = bunny.create_channel # setup faye EM.run { self.faye = Faye::Client.new(config.faye.server) auth_ext = Faye::Authentication::ClientExtension.new(config.faye.secret_token) faye.add_extension(auth_ext) # establish callbacks config.mappings.each do |mapping| sprot, schan = mapping.source.split('://') tprot, tchan = mapping.target.split('://') case [sprot, tprot] * ' -> ' when 'faye -> rabbitmq' then faye2bunny(schan, tchan, mapping) when 'rabbitmq -> faye' then bunny2faye(schan, tchan, mapping) else warn "Unknown mapping: #{sprot} -> #{tprot}" end end } rescue => e puts "FATAL: #{e}" end |