bumpy_bridge 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/bin/bumpy_bridge +15 -0
- data/bumpy_bridge.gemspec +30 -0
- data/lib/bumpy-bridge.rb +1 -0
- data/lib/bumpy_bridge/version.rb +3 -0
- data/lib/bumpy_bridge.rb +76 -0
- metadata +175 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 phil
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
____ ____ _ _
|
2
|
+
| __ ) _ _ _ __ ___ _ __ _ _| __ ) _ __(_) __| | __ _ ___
|
3
|
+
| _ \| | | | '_ ` _ \| '_ \| | | | _ \| '__| |/ _` |/ _` |/ _ \
|
4
|
+
| |_) | |_| | | | | | | |_) | |_| | |_) | | | | (_| | (_| | __/
|
5
|
+
|____/ \__,_|_| |_| |_| .__/ \__, |____/|_| |_|\__,_|\__, |\___|
|
6
|
+
|_| |___/ |___/
|
7
|
+
# Welcome to BumpyBridge
|
8
|
+
|
9
|
+
Bridging RabbitMQ & Faye.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'bumpy_bridge'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install bumpy_bridge
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Example `bumpy_bridge.yml`
|
28
|
+
|
29
|
+
faye:
|
30
|
+
server: http://localhost:9292/faye
|
31
|
+
secret_token: supersecrettoken
|
32
|
+
mappings:
|
33
|
+
- source: faye:///stat
|
34
|
+
target: rabbitmq://stat
|
35
|
+
- source: faye:///register/listener
|
36
|
+
target: rabbitmq://register.listener
|
37
|
+
- source: rabbitmq://asd.f
|
38
|
+
target: faye:///asd/f
|
39
|
+
|
40
|
+
Then run in the directory of the config file
|
41
|
+
|
42
|
+
bumpy_bridge run
|
43
|
+
|
44
|
+
Run with `DEBUG=1` for more output.
|
45
|
+
|
46
|
+
DEBUG=1 bumby_bridge run
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/bumpy_bridge
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/bumpy_bridge', __FILE__)
|
4
|
+
|
5
|
+
base = Dir.pwd
|
6
|
+
config = File.expand_path('bumpy_bridge.yml', base)
|
7
|
+
piddir = File.join(base, 'tmp', 'pids')
|
8
|
+
|
9
|
+
Daemons.run_proc(File.basename(__FILE__), dir: piddir) do
|
10
|
+
Dir.chdir(base)
|
11
|
+
puts 'Establishing BumpyBridge...'
|
12
|
+
BumpyBridge.new(config).run
|
13
|
+
end
|
14
|
+
|
15
|
+
warn "BumpyBridge daemon exiting."
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bumpy_bridge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bumpy_bridge"
|
8
|
+
spec.version = BumpyBridge::VERSION
|
9
|
+
spec.authors = ["phil"]
|
10
|
+
spec.email = ["phil@branch14.org"]
|
11
|
+
spec.description = %q{Bridging RabbitMQ and Faye.}
|
12
|
+
spec.summary = %q{Bridging RabbitMQ and Faye.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "faye"
|
25
|
+
spec.add_dependency 'faye-authentication'
|
26
|
+
spec.add_dependency "bunny"
|
27
|
+
spec.add_dependency "daemons"
|
28
|
+
spec.add_dependency "trickery"
|
29
|
+
|
30
|
+
end
|
data/lib/bumpy-bridge.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../bumpy_bridge', __FILE__)
|
data/lib/bumpy_bridge.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'bumpy_bridge/version'
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require 'faye'
|
8
|
+
require 'faye/authentication'
|
9
|
+
require 'bunny'
|
10
|
+
require 'daemons'
|
11
|
+
require 'trickery'
|
12
|
+
|
13
|
+
DEBUG = ENV['DEBUG']
|
14
|
+
|
15
|
+
class BumpyBridge
|
16
|
+
|
17
|
+
include Trickery::Config
|
18
|
+
|
19
|
+
attr_accessor :config, :faye, :bunny, :bunny_channel
|
20
|
+
|
21
|
+
def initialize(file)
|
22
|
+
self.config = read_config(file)
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
# setup rabbitmq
|
27
|
+
self.bunny = Bunny.new read_timeout: 10, heartbeat: 10
|
28
|
+
bunny.start
|
29
|
+
self.bunny_channel = bunny.create_channel
|
30
|
+
|
31
|
+
# setup faye
|
32
|
+
EM.run {
|
33
|
+
self.faye = Faye::Client.new(config.faye.server)
|
34
|
+
auth_ext = Faye::Authentication::ClientExtension.new(config.faye.secret_token)
|
35
|
+
faye.add_extension(auth_ext)
|
36
|
+
|
37
|
+
# establish callbacks
|
38
|
+
config.mappings.each do |mapping|
|
39
|
+
sprot, schan = mapping.source.split('://')
|
40
|
+
tprot, tchan = mapping.target.split('://')
|
41
|
+
case [sprot, tprot] * ' -> '
|
42
|
+
when 'faye -> rabbitmq' then faye2bunny(schan, tchan, mapping)
|
43
|
+
when 'rabbitmq -> faye' then bunny2faye(schan, tchan, mapping)
|
44
|
+
else warn "Unknown mapping: #{sprot} -> #{tprot}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
}
|
48
|
+
rescue => e
|
49
|
+
puts "FATAL: #{e}"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def faye2bunny(source, target, mapping)
|
55
|
+
puts "faye2rabbitmq [#{source} -> #{target}]" if DEBUG
|
56
|
+
exchange = bunny_channel.fanout(target)
|
57
|
+
faye.subscribe(source) do |data|
|
58
|
+
puts "[#{source} -> #{target}] #{data.inspect}" if DEBUG
|
59
|
+
exchange.publish(JSON.unparse(data))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def bunny2faye(source, target, mapping)
|
64
|
+
puts "rabbitmq2faye [#{source} -> #{target}]" if DEBUG
|
65
|
+
mapping.options ||= {}
|
66
|
+
exchange = bunny_channel.fanout(source)
|
67
|
+
queue = bunny_channel.queue("", exclusive: true)
|
68
|
+
queue.bind exchange
|
69
|
+
queue.subscribe(mapping.options) do |info, prop, body|
|
70
|
+
data = JSON.parse(body)
|
71
|
+
puts "[#{source} -> #{target}] #{data.inspect}" if DEBUG
|
72
|
+
faye.publish(target, data)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bumpy_bridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- phil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faye
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: faye-authentication
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bunny
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: daemons
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: trickery
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Bridging RabbitMQ and Faye.
|
127
|
+
email:
|
128
|
+
- phil@branch14.org
|
129
|
+
executables:
|
130
|
+
- bumpy_bridge
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- .gitignore
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/bumpy_bridge
|
140
|
+
- bumpy_bridge.gemspec
|
141
|
+
- lib/bumpy-bridge.rb
|
142
|
+
- lib/bumpy_bridge.rb
|
143
|
+
- lib/bumpy_bridge/version.rb
|
144
|
+
homepage: ''
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
hash: 3917187243928973188
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
hash: 3917187243928973188
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.23
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: Bridging RabbitMQ and Faye.
|
175
|
+
test_files: []
|