bumpy_bridge 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/bumpy_bridge CHANGED
@@ -3,7 +3,7 @@
3
3
  require File.expand_path('../../lib/bumpy_bridge', __FILE__)
4
4
 
5
5
  base = Dir.pwd
6
- config = File.expand_path(ARGV.last, base)
6
+ config = File.expand_path(ARGV.last || 'bumpy_bridge.yml', base)
7
7
  piddir = File.join(base, 'tmp', 'pids')
8
8
 
9
9
  Daemons.run_proc(File.basename(__FILE__), dir: piddir) do
data/lib/bumpy_bridge.rb CHANGED
@@ -53,19 +53,45 @@ class BumpyBridge
53
53
 
54
54
  def faye2bunny(source, target, mapping)
55
55
  puts "faye2rabbitmq [#{source} -> #{target}]" if DEBUG
56
- exchange = bunny_channel.fanout(target)
56
+ type, name = target.split('/')
57
+
58
+ options = {}
59
+ exchange = nil
60
+
61
+ case type
62
+ when 'exchange'
63
+ exchange = bunny_channel.fanout(name)
64
+ when 'queue'
65
+ queue = bunny_channel.queue(name)
66
+ exchange = bunny_channel.default_exchange
67
+ options[:routing_key] = queue.name
68
+ else raise "Unkown target type: #{type}"
69
+ end
70
+
57
71
  faye.subscribe(source) do |data|
58
72
  puts "[#{source} -> #{target}] #{data.inspect}" if DEBUG
59
- exchange.publish(JSON.unparse(data))
73
+ exchange.publish(JSON.unparse(data), options)
60
74
  end
61
75
  end
62
76
 
63
77
  def bunny2faye(source, target, mapping)
64
78
  puts "rabbitmq2faye [#{source} -> #{target}]" if DEBUG
65
79
  mapping.options ||= {}
66
- exchange = bunny_channel.fanout(source)
67
- queue = bunny_channel.queue("", exclusive: true)
68
- queue.bind exchange
80
+ type, name = source.split('/')
81
+ queue = nil
82
+
83
+ case type
84
+ when 'exchange'
85
+ # create an own queue and bind it to the given exchange
86
+ exchange = bunny_channel.fanout(name)
87
+ queue = bunny_channel.queue('', exclusive: true)
88
+ queue.bind exchange
89
+ when 'queue'
90
+ # pull events directly from the given queue
91
+ queue = bunny_channel.queue(name)
92
+ else raise "Unknown source type: #{type}"
93
+ end
94
+
69
95
  queue.subscribe(mapping.options) do |info, prop, body|
70
96
  data = JSON.parse(body)
71
97
  puts "[#{source} -> #{target}] #{data.inspect}" if DEBUG
@@ -1,3 +1,3 @@
1
1
  class BumpyBridge
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bumpy_bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-10 00:00:00.000000000 Z
12
+ date: 2015-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -156,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  segments:
158
158
  - 0
159
- hash: 2166207992374774766
159
+ hash: -2301075823509589242
160
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  segments:
167
167
  - 0
168
- hash: 2166207992374774766
168
+ hash: -2301075823509589242
169
169
  requirements: []
170
170
  rubyforge_project:
171
171
  rubygems_version: 1.8.23