liebre 0.1.21 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/Gemfile.lock +9 -7
  4. data/{LICENSE → LICENSE.txt} +1 -1
  5. data/README.md +492 -195
  6. data/Rakefile +2 -0
  7. data/lib/liebre.rb +27 -16
  8. data/lib/liebre/actor.rb +11 -0
  9. data/lib/liebre/actor/consumer.rb +80 -0
  10. data/lib/liebre/actor/consumer/callback.rb +34 -0
  11. data/lib/liebre/actor/consumer/core.rb +80 -0
  12. data/lib/liebre/actor/consumer/reporter.rb +84 -0
  13. data/lib/liebre/actor/consumer/resources.rb +47 -0
  14. data/lib/liebre/actor/consumer/resources/config.rb +65 -0
  15. data/lib/liebre/actor/context.rb +40 -0
  16. data/lib/liebre/actor/context/declare.rb +44 -0
  17. data/lib/liebre/actor/context/handler.rb +44 -0
  18. data/lib/liebre/actor/publisher.rb +58 -0
  19. data/lib/liebre/actor/publisher/core.rb +42 -0
  20. data/lib/liebre/actor/publisher/reporter.rb +55 -0
  21. data/lib/liebre/actor/publisher/resources.rb +33 -0
  22. data/lib/liebre/actor/rpc/client.rb +88 -0
  23. data/lib/liebre/actor/rpc/client/core.rb +75 -0
  24. data/lib/liebre/actor/rpc/client/pending.rb +65 -0
  25. data/lib/liebre/actor/rpc/client/reporter.rb +71 -0
  26. data/lib/liebre/actor/rpc/client/resources.rb +62 -0
  27. data/lib/liebre/actor/rpc/client/task.rb +33 -0
  28. data/lib/liebre/actor/rpc/server.rb +74 -0
  29. data/lib/liebre/actor/rpc/server/callback.rb +28 -0
  30. data/lib/liebre/actor/rpc/server/core.rb +75 -0
  31. data/lib/liebre/actor/rpc/server/reporter.rb +72 -0
  32. data/lib/liebre/actor/rpc/server/resources.rb +53 -0
  33. data/lib/liebre/adapter.rb +8 -0
  34. data/lib/liebre/adapter/bunny.rb +23 -0
  35. data/lib/liebre/adapter/bunny/chan.rb +38 -0
  36. data/lib/liebre/adapter/bunny/conn.rb +32 -0
  37. data/lib/liebre/adapter/bunny/exchange.rb +20 -0
  38. data/lib/liebre/adapter/bunny/queue.rb +59 -0
  39. data/lib/liebre/adapter/interface.rb +26 -0
  40. data/lib/liebre/adapter/interface/chan.rb +29 -0
  41. data/lib/liebre/adapter/interface/conn.rb +21 -0
  42. data/lib/liebre/adapter/interface/exchange.rb +13 -0
  43. data/lib/liebre/adapter/interface/queue.rb +37 -0
  44. data/lib/liebre/bridge.rb +72 -0
  45. data/lib/liebre/bridge/channel_builder.rb +36 -0
  46. data/lib/liebre/config.rb +8 -38
  47. data/lib/liebre/engine.rb +61 -0
  48. data/lib/liebre/engine/builder.rb +48 -0
  49. data/lib/liebre/engine/repository.rb +56 -0
  50. data/lib/liebre/engine/state.rb +49 -0
  51. data/lib/liebre/runner.rb +15 -47
  52. data/lib/liebre/version.rb +1 -1
  53. data/liebre.gemspec +9 -7
  54. data/spec/integration/publish_and_consume_spec.rb +71 -0
  55. data/spec/integration/rpc_communication_spec.rb +81 -0
  56. data/spec/integration/start_twice_spec.rb +63 -0
  57. data/spec/liebre/actor/consumer_spec.rb +169 -0
  58. data/spec/liebre/actor/context/declare_spec.rb +69 -0
  59. data/spec/liebre/actor/context/handler_spec.rb +65 -0
  60. data/spec/liebre/actor/publisher_spec.rb +58 -0
  61. data/spec/liebre/actor/rpc/client_spec.rb +126 -0
  62. data/spec/liebre/actor/rpc/server_spec.rb +141 -0
  63. data/spec/liebre/adapter/bunny_spec.rb +66 -0
  64. data/spec/liebre/bridge_spec.rb +54 -0
  65. data/spec/liebre/engine/builder_spec.rb +42 -0
  66. data/spec/liebre/engine_spec.rb +90 -0
  67. data/spec/liebre/version_spec.rb +10 -0
  68. data/spec/spec_helper.rb +2 -9
  69. metadata +97 -58
  70. data/lib/liebre/common.rb +0 -7
  71. data/lib/liebre/common/utils.rb +0 -37
  72. data/lib/liebre/connection_manager.rb +0 -85
  73. data/lib/liebre/publisher.rb +0 -113
  74. data/lib/liebre/runner/consumers.rb +0 -46
  75. data/lib/liebre/runner/starter.rb +0 -44
  76. data/lib/liebre/runner/starter/consumer.rb +0 -129
  77. data/lib/liebre/runner/starter/consumer/handler.rb +0 -35
  78. data/lib/liebre/runner/starter/resources.rb +0 -45
  79. data/lib/liebre/runner/starter/resources/queue_builder.rb +0 -63
  80. data/lib/liebre/runner/starter/rpc.rb +0 -59
  81. data/lib/liebre/tasks.rb +0 -12
  82. data/spec/config/liebre.yml +0 -48
  83. data/spec/config/rabbitmq.yml +0 -35
  84. data/spec/integration_spec.rb +0 -76
  85. data/spec/liebre/config_spec.rb +0 -63
  86. data/spec/liebre/connection_manager_spec.rb +0 -44
  87. data/spec/liebre/publisher_spec.rb +0 -92
  88. data/spec/liebre/runner/consumers_spec.rb +0 -59
  89. data/spec/liebre/runner/starter/consumer_spec.rb +0 -145
  90. data/spec/liebre/runner/starter/resources/queue_builder_spec.rb +0 -69
  91. data/spec/liebre/runner/starter/resources_spec.rb +0 -38
  92. data/spec/liebre/runner/starter/rpc_spec.rb +0 -100
  93. data/spec/liebre/runner/starter_spec.rb +0 -70
  94. 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
@@ -0,0 +1,10 @@
1
+ RSpec.describe Liebre::VERSION do
2
+
3
+ let(:version) { Liebre::VERSION }
4
+ let(:regex) { /\A\d+\.\d+\.\d+\z/ }
5
+
6
+ it 'has semantic format' do
7
+ expect(version).to match regex
8
+ end
9
+
10
+ end
@@ -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.disable_monkey_patching!
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.21
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-02-22 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: bunny
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: 2.5.1
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: '2.5'
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: 2.5.1
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: rspec
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: pry
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: rake
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/common.rb
105
- - lib/liebre/common/utils.rb
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/connection_manager.rb
108
- - lib/liebre/publisher.rb
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/config/liebre.yml
121
- - spec/config/rabbitmq.yml
122
- - spec/integration_spec.rb
123
- - spec/liebre/config_spec.rb
124
- - spec/liebre/connection_manager_spec.rb
125
- - spec/liebre/publisher_spec.rb
126
- - spec/liebre/runner/consumers_spec.rb
127
- - spec/liebre/runner/starter/consumer_spec.rb
128
- - spec/liebre/runner/starter/resources/queue_builder_spec.rb
129
- - spec/liebre/runner/starter/resources_spec.rb
130
- - spec/liebre/runner/starter/rpc_spec.rb
131
- - spec/liebre/runner/starter_spec.rb
132
- - spec/liebre/runner_spec.rb
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: https://github.com/iadbox/liebre
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.5.1
193
+ rubygems_version: 2.4.8
155
194
  signing_key:
156
195
  specification_version: 4
157
- summary: A gem to consume and publish to RabbitMQ based on Bunny, creates a thread
158
- for every consumer
196
+ summary: Some abstractions to interact with a AMQP broker
159
197
  test_files:
160
- - spec/config/liebre.yml
161
- - spec/config/rabbitmq.yml
162
- - spec/integration_spec.rb
163
- - spec/liebre/config_spec.rb
164
- - spec/liebre/connection_manager_spec.rb
165
- - spec/liebre/publisher_spec.rb
166
- - spec/liebre/runner/consumers_spec.rb
167
- - spec/liebre/runner/starter/consumer_spec.rb
168
- - spec/liebre/runner/starter/resources/queue_builder_spec.rb
169
- - spec/liebre/runner/starter/resources_spec.rb
170
- - spec/liebre/runner/starter/rpc_spec.rb
171
- - spec/liebre/runner/starter_spec.rb
172
- - spec/liebre/runner_spec.rb
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
@@ -1,7 +0,0 @@
1
- module Liebre
2
- module Common
3
-
4
- autoload :Utils, 'liebre/common/utils'
5
-
6
- end
7
- end
@@ -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