liebre 0.1.21 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile.lock +9 -7
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +492 -195
- data/Rakefile +2 -0
- data/lib/liebre.rb +27 -16
- data/lib/liebre/actor.rb +11 -0
- data/lib/liebre/actor/consumer.rb +80 -0
- data/lib/liebre/actor/consumer/callback.rb +34 -0
- data/lib/liebre/actor/consumer/core.rb +80 -0
- data/lib/liebre/actor/consumer/reporter.rb +84 -0
- data/lib/liebre/actor/consumer/resources.rb +47 -0
- data/lib/liebre/actor/consumer/resources/config.rb +65 -0
- data/lib/liebre/actor/context.rb +40 -0
- data/lib/liebre/actor/context/declare.rb +44 -0
- data/lib/liebre/actor/context/handler.rb +44 -0
- data/lib/liebre/actor/publisher.rb +58 -0
- data/lib/liebre/actor/publisher/core.rb +42 -0
- data/lib/liebre/actor/publisher/reporter.rb +55 -0
- data/lib/liebre/actor/publisher/resources.rb +33 -0
- data/lib/liebre/actor/rpc/client.rb +88 -0
- data/lib/liebre/actor/rpc/client/core.rb +75 -0
- data/lib/liebre/actor/rpc/client/pending.rb +65 -0
- data/lib/liebre/actor/rpc/client/reporter.rb +71 -0
- data/lib/liebre/actor/rpc/client/resources.rb +62 -0
- data/lib/liebre/actor/rpc/client/task.rb +33 -0
- data/lib/liebre/actor/rpc/server.rb +74 -0
- data/lib/liebre/actor/rpc/server/callback.rb +28 -0
- data/lib/liebre/actor/rpc/server/core.rb +75 -0
- data/lib/liebre/actor/rpc/server/reporter.rb +72 -0
- data/lib/liebre/actor/rpc/server/resources.rb +53 -0
- data/lib/liebre/adapter.rb +8 -0
- data/lib/liebre/adapter/bunny.rb +23 -0
- data/lib/liebre/adapter/bunny/chan.rb +38 -0
- data/lib/liebre/adapter/bunny/conn.rb +32 -0
- data/lib/liebre/adapter/bunny/exchange.rb +20 -0
- data/lib/liebre/adapter/bunny/queue.rb +59 -0
- data/lib/liebre/adapter/interface.rb +26 -0
- data/lib/liebre/adapter/interface/chan.rb +29 -0
- data/lib/liebre/adapter/interface/conn.rb +21 -0
- data/lib/liebre/adapter/interface/exchange.rb +13 -0
- data/lib/liebre/adapter/interface/queue.rb +37 -0
- data/lib/liebre/bridge.rb +72 -0
- data/lib/liebre/bridge/channel_builder.rb +36 -0
- data/lib/liebre/config.rb +8 -38
- data/lib/liebre/engine.rb +61 -0
- data/lib/liebre/engine/builder.rb +48 -0
- data/lib/liebre/engine/repository.rb +56 -0
- data/lib/liebre/engine/state.rb +49 -0
- data/lib/liebre/runner.rb +15 -47
- data/lib/liebre/version.rb +1 -1
- data/liebre.gemspec +9 -7
- data/spec/integration/publish_and_consume_spec.rb +71 -0
- data/spec/integration/rpc_communication_spec.rb +81 -0
- data/spec/integration/start_twice_spec.rb +63 -0
- data/spec/liebre/actor/consumer_spec.rb +169 -0
- data/spec/liebre/actor/context/declare_spec.rb +69 -0
- data/spec/liebre/actor/context/handler_spec.rb +65 -0
- data/spec/liebre/actor/publisher_spec.rb +58 -0
- data/spec/liebre/actor/rpc/client_spec.rb +126 -0
- data/spec/liebre/actor/rpc/server_spec.rb +141 -0
- data/spec/liebre/adapter/bunny_spec.rb +66 -0
- data/spec/liebre/bridge_spec.rb +54 -0
- data/spec/liebre/engine/builder_spec.rb +42 -0
- data/spec/liebre/engine_spec.rb +90 -0
- data/spec/liebre/version_spec.rb +10 -0
- data/spec/spec_helper.rb +2 -9
- metadata +97 -58
- data/lib/liebre/common.rb +0 -7
- data/lib/liebre/common/utils.rb +0 -37
- data/lib/liebre/connection_manager.rb +0 -85
- data/lib/liebre/publisher.rb +0 -113
- data/lib/liebre/runner/consumers.rb +0 -46
- data/lib/liebre/runner/starter.rb +0 -44
- data/lib/liebre/runner/starter/consumer.rb +0 -129
- data/lib/liebre/runner/starter/consumer/handler.rb +0 -35
- data/lib/liebre/runner/starter/resources.rb +0 -45
- data/lib/liebre/runner/starter/resources/queue_builder.rb +0 -63
- data/lib/liebre/runner/starter/rpc.rb +0 -59
- data/lib/liebre/tasks.rb +0 -12
- data/spec/config/liebre.yml +0 -48
- data/spec/config/rabbitmq.yml +0 -35
- data/spec/integration_spec.rb +0 -76
- data/spec/liebre/config_spec.rb +0 -63
- data/spec/liebre/connection_manager_spec.rb +0 -44
- data/spec/liebre/publisher_spec.rb +0 -92
- data/spec/liebre/runner/consumers_spec.rb +0 -59
- data/spec/liebre/runner/starter/consumer_spec.rb +0 -145
- data/spec/liebre/runner/starter/resources/queue_builder_spec.rb +0 -69
- data/spec/liebre/runner/starter/resources_spec.rb +0 -38
- data/spec/liebre/runner/starter/rpc_spec.rb +0 -100
- data/spec/liebre/runner/starter_spec.rb +0 -70
- data/spec/liebre/runner_spec.rb +0 -54
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'concurrent'
|
2
|
+
|
3
|
+
RSpec.describe Liebre::Engine::Builder do
|
4
|
+
|
5
|
+
let(:bridge) { double 'bridge' }
|
6
|
+
let(:type) { :publishers }
|
7
|
+
let(:name) { :foo }
|
8
|
+
let(:opts) { double 'opts' }
|
9
|
+
|
10
|
+
let(:context_class) { double 'context_class' }
|
11
|
+
let(:publisher_class) { double 'publisher_class' }
|
12
|
+
|
13
|
+
let :dependencies do
|
14
|
+
{:context => context_class,
|
15
|
+
:actors => {:publishers => publisher_class}}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:logger) { double 'logger' }
|
19
|
+
let(:config) { double 'config', :logger => logger }
|
20
|
+
|
21
|
+
subject { described_class.new(bridge, type, name, opts, config, dependencies) }
|
22
|
+
|
23
|
+
describe '#call' do
|
24
|
+
let(:chan) { double 'chan' }
|
25
|
+
let(:context) { double 'context' }
|
26
|
+
let(:publisher) { double 'publisher' }
|
27
|
+
|
28
|
+
it 'instantiates the actor and the context properly' do
|
29
|
+
expect(bridge).to receive(:open_channel).
|
30
|
+
with(opts).and_return(chan)
|
31
|
+
|
32
|
+
expect(context_class).to receive(:new).
|
33
|
+
with(chan, name, opts, config).and_return(context)
|
34
|
+
|
35
|
+
expect(publisher_class).to receive(:new).
|
36
|
+
with(context).and_return(publisher)
|
37
|
+
|
38
|
+
expect(subject.call).to eq publisher
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'concurrent'
|
2
|
+
|
3
|
+
RSpec.describe Liebre::Engine do
|
4
|
+
|
5
|
+
let(:publisher_1_opts) { double 'publisher_1_opts' }
|
6
|
+
let(:publisher_2_opts) { double 'publisher_2_opts' }
|
7
|
+
let(:consumer_opts) { double 'consumer_opts' }
|
8
|
+
|
9
|
+
let :actors do
|
10
|
+
{:publishers => {
|
11
|
+
:one => publisher_1_opts,
|
12
|
+
:two => publisher_2_opts},
|
13
|
+
:consumers => {
|
14
|
+
:three => consumer_opts}}
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:config) { double 'config', :actors => actors }
|
18
|
+
|
19
|
+
subject { described_class.new(config) }
|
20
|
+
|
21
|
+
let(:bridge) { double 'bridge' }
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(Liebre::Bridge).to receive(:new).
|
25
|
+
with(config).and_return(bridge)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#start, #clean, #repo and #stop' do
|
29
|
+
let(:publisher_1) { double 'publisher_1' }
|
30
|
+
let(:publisher_2) { double 'publisher_2' }
|
31
|
+
let(:consumer) { double 'consumer' }
|
32
|
+
|
33
|
+
let(:builder_1) { double 'builder_1', :call => publisher_1 }
|
34
|
+
let(:builder_2) { double 'builder_2', :call => publisher_2 }
|
35
|
+
let(:builder_3) { double 'builder_3', :call => consumer }
|
36
|
+
|
37
|
+
it 'starts the bridge and all actors' do
|
38
|
+
expect(bridge).to receive(:start).
|
39
|
+
twice
|
40
|
+
|
41
|
+
expect(described_class::Builder).to receive(:new).
|
42
|
+
with(bridge, :publishers, :one, publisher_1_opts, config).
|
43
|
+
and_return(builder_1).
|
44
|
+
twice
|
45
|
+
|
46
|
+
expect(described_class::Builder).to receive(:new).
|
47
|
+
with(bridge, :publishers, :two, publisher_2_opts, config).
|
48
|
+
and_return(builder_2).
|
49
|
+
twice
|
50
|
+
|
51
|
+
expect(described_class::Builder).to receive(:new).
|
52
|
+
with(bridge, :consumers, :three, consumer_opts, config).
|
53
|
+
and_return(builder_3).
|
54
|
+
twice
|
55
|
+
|
56
|
+
expect(publisher_1).to receive(:start)
|
57
|
+
expect(publisher_2).to receive(:start)
|
58
|
+
expect(consumer ).to receive(:start)
|
59
|
+
|
60
|
+
subject.start
|
61
|
+
|
62
|
+
expect(publisher_1).to receive(:clean)
|
63
|
+
expect(publisher_2).to receive(:clean)
|
64
|
+
expect(consumer ).to receive(:clean)
|
65
|
+
|
66
|
+
subject.clean
|
67
|
+
|
68
|
+
repo = subject.repo
|
69
|
+
expect(repo.publisher(:one) ).to eq publisher_1
|
70
|
+
expect(repo.publisher(:two) ).to eq publisher_2
|
71
|
+
expect(repo.consumer(:three)).to eq consumer
|
72
|
+
|
73
|
+
repo = subject.repo
|
74
|
+
expect(repo.publisher(:one) ).to eq publisher_1
|
75
|
+
expect(repo.publisher(:two) ).to eq publisher_2
|
76
|
+
expect(repo.consumer(:three)).to eq consumer
|
77
|
+
|
78
|
+
expect(publisher_1).to receive(:stop)
|
79
|
+
expect(publisher_2).to receive(:stop)
|
80
|
+
expect(consumer ).to receive(:stop)
|
81
|
+
|
82
|
+
expect(bridge).to receive(:stop)
|
83
|
+
|
84
|
+
subject.stop
|
85
|
+
|
86
|
+
expect(repo.all).to eq []
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,16 @@
|
|
1
|
-
require 'pry'
|
2
1
|
require 'liebre'
|
2
|
+
require 'pry'
|
3
3
|
|
4
4
|
RSpec.configure do |config|
|
5
|
-
|
6
|
-
config.before :each do
|
7
|
-
Liebre::Config.env = "test"
|
8
|
-
end
|
9
5
|
|
10
6
|
config.expect_with :rspec do |expectations|
|
11
|
-
# Best error messages on chained expectations
|
12
7
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
13
8
|
end
|
14
9
|
|
15
10
|
config.mock_with :rspec do |mocks|
|
16
|
-
# Prevents you from stubbing a method that does not exist on a real object
|
17
11
|
mocks.verify_partial_doubles = true
|
18
12
|
end
|
19
13
|
|
20
|
-
config.
|
21
|
-
config.order = :random
|
14
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
22
15
|
|
23
16
|
end
|
metadata
CHANGED
@@ -1,36 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liebre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jcabotc
|
8
|
-
- graimon
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2017-
|
11
|
+
date: 2017-03-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: concurrent-ruby
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '2.5'
|
21
17
|
- - ">="
|
22
18
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
19
|
+
version: '0'
|
24
20
|
type: :runtime
|
25
21
|
prerelease: false
|
26
22
|
version_requirements: !ruby/object:Gem::Requirement
|
27
23
|
requirements:
|
28
|
-
- - "
|
24
|
+
- - ">="
|
29
25
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bunny
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
34
41
|
- !ruby/object:Gem::Dependency
|
35
42
|
name: bundler
|
36
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +53,7 @@ dependencies:
|
|
46
53
|
- !ruby/object:Gem::Version
|
47
54
|
version: '1.6'
|
48
55
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
56
|
+
name: rake
|
50
57
|
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
59
|
- - ">="
|
@@ -60,7 +67,7 @@ dependencies:
|
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: '0'
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
70
|
+
name: rspec
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
72
|
requirements:
|
66
73
|
- - ">="
|
@@ -74,7 +81,7 @@ dependencies:
|
|
74
81
|
- !ruby/object:Gem::Version
|
75
82
|
version: '0'
|
76
83
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
84
|
+
name: pry
|
78
85
|
requirement: !ruby/object:Gem::Requirement
|
79
86
|
requirements:
|
80
87
|
- - ">="
|
@@ -90,48 +97,80 @@ dependencies:
|
|
90
97
|
description:
|
91
98
|
email:
|
92
99
|
- jcabot@gmail.com
|
93
|
-
- graimon@gmail.com
|
94
100
|
executables: []
|
95
101
|
extensions: []
|
96
102
|
extra_rdoc_files: []
|
97
103
|
files:
|
98
104
|
- ".gitignore"
|
105
|
+
- ".rspec"
|
99
106
|
- Gemfile
|
100
107
|
- Gemfile.lock
|
101
|
-
- LICENSE
|
108
|
+
- LICENSE.txt
|
102
109
|
- README.md
|
110
|
+
- Rakefile
|
103
111
|
- lib/liebre.rb
|
104
|
-
- lib/liebre/
|
105
|
-
- lib/liebre/
|
112
|
+
- lib/liebre/actor.rb
|
113
|
+
- lib/liebre/actor/consumer.rb
|
114
|
+
- lib/liebre/actor/consumer/callback.rb
|
115
|
+
- lib/liebre/actor/consumer/core.rb
|
116
|
+
- lib/liebre/actor/consumer/reporter.rb
|
117
|
+
- lib/liebre/actor/consumer/resources.rb
|
118
|
+
- lib/liebre/actor/consumer/resources/config.rb
|
119
|
+
- lib/liebre/actor/context.rb
|
120
|
+
- lib/liebre/actor/context/declare.rb
|
121
|
+
- lib/liebre/actor/context/handler.rb
|
122
|
+
- lib/liebre/actor/publisher.rb
|
123
|
+
- lib/liebre/actor/publisher/core.rb
|
124
|
+
- lib/liebre/actor/publisher/reporter.rb
|
125
|
+
- lib/liebre/actor/publisher/resources.rb
|
126
|
+
- lib/liebre/actor/rpc/client.rb
|
127
|
+
- lib/liebre/actor/rpc/client/core.rb
|
128
|
+
- lib/liebre/actor/rpc/client/pending.rb
|
129
|
+
- lib/liebre/actor/rpc/client/reporter.rb
|
130
|
+
- lib/liebre/actor/rpc/client/resources.rb
|
131
|
+
- lib/liebre/actor/rpc/client/task.rb
|
132
|
+
- lib/liebre/actor/rpc/server.rb
|
133
|
+
- lib/liebre/actor/rpc/server/callback.rb
|
134
|
+
- lib/liebre/actor/rpc/server/core.rb
|
135
|
+
- lib/liebre/actor/rpc/server/reporter.rb
|
136
|
+
- lib/liebre/actor/rpc/server/resources.rb
|
137
|
+
- lib/liebre/adapter.rb
|
138
|
+
- lib/liebre/adapter/bunny.rb
|
139
|
+
- lib/liebre/adapter/bunny/chan.rb
|
140
|
+
- lib/liebre/adapter/bunny/conn.rb
|
141
|
+
- lib/liebre/adapter/bunny/exchange.rb
|
142
|
+
- lib/liebre/adapter/bunny/queue.rb
|
143
|
+
- lib/liebre/adapter/interface.rb
|
144
|
+
- lib/liebre/adapter/interface/chan.rb
|
145
|
+
- lib/liebre/adapter/interface/conn.rb
|
146
|
+
- lib/liebre/adapter/interface/exchange.rb
|
147
|
+
- lib/liebre/adapter/interface/queue.rb
|
148
|
+
- lib/liebre/bridge.rb
|
149
|
+
- lib/liebre/bridge/channel_builder.rb
|
106
150
|
- lib/liebre/config.rb
|
107
|
-
- lib/liebre/
|
108
|
-
- lib/liebre/
|
151
|
+
- lib/liebre/engine.rb
|
152
|
+
- lib/liebre/engine/builder.rb
|
153
|
+
- lib/liebre/engine/repository.rb
|
154
|
+
- lib/liebre/engine/state.rb
|
109
155
|
- lib/liebre/runner.rb
|
110
|
-
- lib/liebre/runner/consumers.rb
|
111
|
-
- lib/liebre/runner/starter.rb
|
112
|
-
- lib/liebre/runner/starter/consumer.rb
|
113
|
-
- lib/liebre/runner/starter/consumer/handler.rb
|
114
|
-
- lib/liebre/runner/starter/resources.rb
|
115
|
-
- lib/liebre/runner/starter/resources/queue_builder.rb
|
116
|
-
- lib/liebre/runner/starter/rpc.rb
|
117
|
-
- lib/liebre/tasks.rb
|
118
156
|
- lib/liebre/version.rb
|
119
157
|
- liebre.gemspec
|
120
|
-
- spec/
|
121
|
-
- spec/
|
122
|
-
- spec/
|
123
|
-
- spec/liebre/
|
124
|
-
- spec/liebre/
|
125
|
-
- spec/liebre/
|
126
|
-
- spec/liebre/
|
127
|
-
- spec/liebre/
|
128
|
-
- spec/liebre/
|
129
|
-
- spec/liebre/
|
130
|
-
- spec/liebre/
|
131
|
-
- spec/liebre/
|
132
|
-
- spec/liebre/
|
158
|
+
- spec/integration/publish_and_consume_spec.rb
|
159
|
+
- spec/integration/rpc_communication_spec.rb
|
160
|
+
- spec/integration/start_twice_spec.rb
|
161
|
+
- spec/liebre/actor/consumer_spec.rb
|
162
|
+
- spec/liebre/actor/context/declare_spec.rb
|
163
|
+
- spec/liebre/actor/context/handler_spec.rb
|
164
|
+
- spec/liebre/actor/publisher_spec.rb
|
165
|
+
- spec/liebre/actor/rpc/client_spec.rb
|
166
|
+
- spec/liebre/actor/rpc/server_spec.rb
|
167
|
+
- spec/liebre/adapter/bunny_spec.rb
|
168
|
+
- spec/liebre/bridge_spec.rb
|
169
|
+
- spec/liebre/engine/builder_spec.rb
|
170
|
+
- spec/liebre/engine_spec.rb
|
171
|
+
- spec/liebre/version_spec.rb
|
133
172
|
- spec/spec_helper.rb
|
134
|
-
homepage:
|
173
|
+
homepage: ''
|
135
174
|
licenses:
|
136
175
|
- MIT
|
137
176
|
metadata: {}
|
@@ -151,23 +190,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
190
|
version: '0'
|
152
191
|
requirements: []
|
153
192
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.4.
|
193
|
+
rubygems_version: 2.4.8
|
155
194
|
signing_key:
|
156
195
|
specification_version: 4
|
157
|
-
summary:
|
158
|
-
for every consumer
|
196
|
+
summary: Some abstractions to interact with a AMQP broker
|
159
197
|
test_files:
|
160
|
-
- spec/
|
161
|
-
- spec/
|
162
|
-
- spec/
|
163
|
-
- spec/liebre/
|
164
|
-
- spec/liebre/
|
165
|
-
- spec/liebre/
|
166
|
-
- spec/liebre/
|
167
|
-
- spec/liebre/
|
168
|
-
- spec/liebre/
|
169
|
-
- spec/liebre/
|
170
|
-
- spec/liebre/
|
171
|
-
- spec/liebre/
|
172
|
-
- spec/liebre/
|
198
|
+
- spec/integration/publish_and_consume_spec.rb
|
199
|
+
- spec/integration/rpc_communication_spec.rb
|
200
|
+
- spec/integration/start_twice_spec.rb
|
201
|
+
- spec/liebre/actor/consumer_spec.rb
|
202
|
+
- spec/liebre/actor/context/declare_spec.rb
|
203
|
+
- spec/liebre/actor/context/handler_spec.rb
|
204
|
+
- spec/liebre/actor/publisher_spec.rb
|
205
|
+
- spec/liebre/actor/rpc/client_spec.rb
|
206
|
+
- spec/liebre/actor/rpc/server_spec.rb
|
207
|
+
- spec/liebre/adapter/bunny_spec.rb
|
208
|
+
- spec/liebre/bridge_spec.rb
|
209
|
+
- spec/liebre/engine/builder_spec.rb
|
210
|
+
- spec/liebre/engine_spec.rb
|
211
|
+
- spec/liebre/version_spec.rb
|
173
212
|
- spec/spec_helper.rb
|
data/lib/liebre/common.rb
DELETED
data/lib/liebre/common/utils.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Liebre
|
2
|
-
module Common
|
3
|
-
module Utils
|
4
|
-
|
5
|
-
@@mutex = Mutex.new
|
6
|
-
|
7
|
-
def self.mutex_sync
|
8
|
-
unless @@mutex.locked?
|
9
|
-
@@mutex.synchronize do
|
10
|
-
yield
|
11
|
-
end
|
12
|
-
else
|
13
|
-
yield
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.create_exchange channel, config
|
18
|
-
exchange_name = config.fetch "name"
|
19
|
-
|
20
|
-
type = config.fetch("type")
|
21
|
-
opts = config.fetch("opts", {})
|
22
|
-
exchange_opts = symbolize_keys(opts.merge("type" => type))
|
23
|
-
|
24
|
-
mutex_sync { channel.exchange exchange_name, exchange_opts }
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.symbolize_keys hash
|
28
|
-
result = {}
|
29
|
-
hash.each do |k, v|
|
30
|
-
result[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v
|
31
|
-
end
|
32
|
-
result
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
require "bunny"
|
3
|
-
require "singleton"
|
4
|
-
|
5
|
-
module Liebre
|
6
|
-
class ConnectionManager
|
7
|
-
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@path = Liebre::Config.connection_path
|
12
|
-
@connections = {}
|
13
|
-
@channels = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def start
|
17
|
-
Common::Utils.mutex_sync do
|
18
|
-
initialize_connections
|
19
|
-
connections.each do |connection_name, bunny|
|
20
|
-
begin
|
21
|
-
bunny.start
|
22
|
-
rescue => e
|
23
|
-
$logger.error("#{self.class.name}: Can't connect to #{connection_name} instance")
|
24
|
-
$logger.error(e.message + "\n" + e.backtrace.join("\n"))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def ensure_started
|
31
|
-
all_open = !@connections.empty? and @connections.all? do |_, bunny|
|
32
|
-
bunny.open?
|
33
|
-
end
|
34
|
-
restart unless all_open
|
35
|
-
end
|
36
|
-
|
37
|
-
def restart
|
38
|
-
stop
|
39
|
-
start
|
40
|
-
end
|
41
|
-
|
42
|
-
def get connection_name
|
43
|
-
connections[connection_name.to_sym]
|
44
|
-
end
|
45
|
-
|
46
|
-
def channel_for connection_name, consumer_pool_size = 1
|
47
|
-
Common::Utils.mutex_sync do
|
48
|
-
channels[connection_name] ||= begin
|
49
|
-
get(connection_name).create_channel nil, consumer_pool_size
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def stop
|
55
|
-
Common::Utils.mutex_sync do
|
56
|
-
connections.each do |_, bunny|
|
57
|
-
if bunny and bunny.open?
|
58
|
-
bunny.close
|
59
|
-
end
|
60
|
-
end
|
61
|
-
connections.clear
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def initialize_connections
|
68
|
-
config.each do |name, conf|
|
69
|
-
@connections[name.to_sym] = connection_for(conf)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def connection_for config
|
74
|
-
Bunny.new(config)
|
75
|
-
end
|
76
|
-
|
77
|
-
def config
|
78
|
-
result = YAML.load_file(path)
|
79
|
-
Liebre.env ? result.fetch(Liebre.env) : result
|
80
|
-
end
|
81
|
-
|
82
|
-
attr_reader :path, :connections, :channels
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|